fix genlocale

This commit is contained in:
Ftps 2023-08-29 15:41:19 +09:00
parent 19670917c6
commit ea1047ec8e
3 changed files with 10 additions and 8 deletions

View File

@ -13,8 +13,8 @@ jobs:
- name: Run locale generation
run: |
python3 lib/i18n/scan_i18n.py
cd lib/i18n && python3 locale_diff.py
python3 i18n/scan_i18n.py
python3 i18n/locale_diff.py
- name: Commit back
if: ${{ !github.head_ref }}

View File

@ -8,7 +8,9 @@ standard_file = "i18n/locale/zh_CN.json"
# Find all JSON files in the directory
dir_path = "i18n/locale/"
languages = [
f for f in os.listdir(dir_path) if f.endswith(".json") and f != standard_file
os.path.join(dir_path, f)
for f in os.listdir(dir_path)
if f.endswith(".json") and f != standard_file
]
# Load the standard file
@ -18,7 +20,7 @@ with open(standard_file, "r", encoding="utf-8") as f:
# Loop through each language file
for lang_file in languages:
# Load the language file
with open(dir_path + lang_file, "r", encoding="utf-8") as f:
with open(lang_file, "r", encoding="utf-8") as f:
lang_data = json.load(f, object_pairs_hook=OrderedDict)
# Find the difference between the language file and the standard file
@ -40,6 +42,6 @@ for lang_file in languages:
)
# Save the updated language file
with open(dir_path + lang_file, "w", encoding="utf-8") as f:
with open(lang_file, "w", encoding="utf-8") as f:
json.dump(lang_data, f, ensure_ascii=False, indent=4, sort_keys=True)
f.write("\n")

View File

@ -49,8 +49,8 @@ print()
print("Total unique:", len(code_keys))
standard_file = "zh_CN.json"
with open(f"lib/i18n/{standard_file}", "r", encoding="utf-8") as f:
standard_file = "i18n/locale/zh_CN.json"
with open(standard_file, "r", encoding="utf-8") as f:
standard_data = json.load(f, object_pairs_hook=OrderedDict)
standard_keys = set(standard_data.keys())
@ -70,6 +70,6 @@ for s in strings:
code_keys_dict[s] = s
# write back
with open(f"lib/i18n/{standard_file}", "w", encoding="utf-8") as f:
with open(standard_file, "w", encoding="utf-8") as f:
json.dump(code_keys_dict, f, ensure_ascii=False, indent=4, sort_keys=True)
f.write("\n")