From ea1047ec8e72cc03b2db915f39059a0b80f0a748 Mon Sep 17 00:00:00 2001 From: Ftps <63702646+Tps-F@users.noreply.github.com> Date: Tue, 29 Aug 2023 15:41:19 +0900 Subject: [PATCH] fix genlocale --- .github/workflows/genlocale.yml | 4 ++-- i18n/locale_diff.py | 8 +++++--- i18n/{locale => }/scan_i18n.py | 6 +++--- 3 files changed, 10 insertions(+), 8 deletions(-) rename i18n/{locale => }/scan_i18n.py (91%) diff --git a/.github/workflows/genlocale.yml b/.github/workflows/genlocale.yml index ebed03a..d678a15 100644 --- a/.github/workflows/genlocale.yml +++ b/.github/workflows/genlocale.yml @@ -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 }} diff --git a/i18n/locale_diff.py b/i18n/locale_diff.py index 2cb2ec5..7c7d05c 100644 --- a/i18n/locale_diff.py +++ b/i18n/locale_diff.py @@ -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") diff --git a/i18n/locale/scan_i18n.py b/i18n/scan_i18n.py similarity index 91% rename from i18n/locale/scan_i18n.py rename to i18n/scan_i18n.py index b5fe055..f3e52cf 100644 --- a/i18n/locale/scan_i18n.py +++ b/i18n/scan_i18n.py @@ -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")