refactor: Add suffixes to translation file.

This commit is contained in:
Terry Geng 2020-07-12 11:55:04 +08:00
parent 350eb0a586
commit 9f2c4a2afd
No known key found for this signature in database
GPG Key ID: F982F8EA1DF720E7
4 changed files with 15 additions and 15 deletions

View File

@ -8,9 +8,9 @@ lang_dict = {}
def load_lang(lang):
global lang_dict, default_lang_dict
with open("lang/en_US", "r") as f:
with open("lang/en_US.json", "r") as f:
default_lang_dict = json.load(f)
with open(f"lang/{lang}", "r") as f:
with open(f"lang/{lang}.json", "r") as f:
lang_dict = json.load(f)

View File

@ -4,8 +4,8 @@
"added_tags_to_all": "Added tags <i>{tags}</i> to songs on the playlist.",
"admin_help": "<h3>Admin command</h3>\n<b>Bot</b>\n<ul>\n<li><b>!<u>k</u>ill </b> - kill the bot</li>\n<li><b>!update </b> - update the bot</li>\n<li><b>!userban </b> {user} - ban a user</li>\n<li><b>!userunban </b> {user} - unban a user</li>\n<li><b>!urlbanlist </b> - list banned url</li>\n<li><b>!urlban </b> [{url}] - ban {url} (or current item's url by default) and remove this url from the library.</li>\n<li><b>!urlunban </b> {url} - unban {url}</li>\n<li><b>!rescan </b> {url} - rebuild local music file cache</li>\n<li><b>!dropdatabase</b> - clear the entire database, you will lose all settings and music library.</li>\n</ul>\n<b>Web Interface</b>\n<ul>\n<li><b>!<u>webuserlist</u></b> - list all users that have the permission of accessing the web interface, if auth mode is 'password'.</li>\n<li><b>!<u>webuseradd</u> {nick name}</b> - grant the user with {nick name} the access to the web interface, if auth mode is 'password'.</li>\n<li><b>!<u>webuserdel</u> {nick name}</b> - revoke the access to the web interface of {nick name}, if auth mode is 'password'.</li>\n<li><b>!update </b> - update the bot</li>\n<li><b>!userban </b> {user} - ban a user</li>\n</ul>",
"auto_paused": "Use <i>!play</i> to resume music!",
"bad_command": "{{command}}: command not found.",
"bad_parameter": "{command}: invalid parameter.",
"bad_command": "<i>{command}</i>: command not found.",
"bad_parameter": "<i>{command}</i>: invalid parameter.",
"bad_url": "Bad URL requested.",
"cache_refreshed": "Cache refreshed!",
"change_ducking_volume": "Volume on ducking set to {volume} by {user}.",

View File

@ -39,30 +39,30 @@ def fetch_translation(r_client, r_secret):
params = {'locale': lang_code,
'format': 'jsonnested'}
r = requests.get(f"{base_url}/projects/{project_id}/exports", params=params, headers=headers)
with open(lang_code, "wb") as f:
with open(lang_code + ".json", "wb") as f:
f.write(r.content)
def push_strings(w_client, w_secret):
print("Pushing local en_US file into the remote host...")
print("Pushing local translation files into the remote host...")
headers = get_access_header(w_client, w_secret)
lang_files = os.listdir('.')
lang_list = []
for lang_file in lang_files:
match = re.search("[a-z]{2}_[A-Z]{2}", lang_file)
match = re.search("([a-z]{2}_[A-Z]{2})\.json", lang_file)
if match:
lang_list.append(lang_file)
lang_list.append(match[1])
for lang_file in lang_list:
print(f" - Pushing {lang_file}")
for lang in lang_list:
print(f" - Pushing {lang}")
params = {'locale': lang_file,
params = {'locale': lang,
'format': 'jsonnested'}
files = {'file': open(lang_file, 'r')}
files = {'file': open(lang + ".json", 'r')}
r = requests.post(f"{base_url}/projects/{project_id}/imports", params=params, headers=headers, files=files)
assert r.status_code == 200, f"Unable to push {lang_file} into remote host. {r.status_code}"
assert r.status_code == 200, f"Unable to push {lang} into remote host. {r.status_code}"
if __name__ == "__main__":

View File

@ -419,9 +419,9 @@ def get_supported_language():
lang_files = os.listdir('lang')
lang_list = []
for lang_file in lang_files:
match = re.search("[a-z]{2}_[A-Z]{2}", lang_file)
match = re.search("([a-z]{2}_[A-Z]{2})\.json", lang_file)
if match:
lang_list.append(lang_file)
lang_list.append(match[1])
return lang_list