RCV/locale/locale_diff.py
源文雨 71bf6a4156
feat: link zh_TW.json to zh_HK.json & zh_SG.json (#64)
* optimize: 精简未用到的配置项并在特征提取初步引入mps

* add cmd argument: --noautoopen

* fix: i18n

* fix

* fix

* add genlocale workflow

* add unitest

* fix

* fix

* fix

* 优化笔记本

* reintroduce Push changes

* disable genlocale on non-main branch

* 将笔记本checkout改为stable

* 优化代码结构

* make lint happy

* make lint happy

* 优化

* 优化

* 优化

* fix path on windows okey pack

* fix

* fix

* revert

* revert

* revert

* fix: extract locale regex

* feat: link zh_TW.json to zh_HK.json & zh_SG.json

* fix #50: set default language to en_US
2023-04-15 13:45:01 +00:00

43 lines
1.4 KiB
Python

import json
from collections import OrderedDict
# Define the standard file name
standard_file = "zh_CN.json"
# Define the list of supported languages
# zh_HK.json and zh_SG.json is not included in the list
# because they are symbolinks to zh_TW.json
languages = ["zh_TW.json", "ja_JP.json", "en_US.json"]
# Load the standard file
with open(standard_file, "r", encoding="utf-8") as f:
standard_data = json.load(f, object_pairs_hook=OrderedDict)
# Loop through each language file
for lang_file in languages:
# Load the language file
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
diff = set(standard_data.keys()) - set(lang_data.keys())
miss = set(lang_data.keys()) - set(standard_data.keys())
# Add any missing keys to the language file
for key in diff:
lang_data[key] = key
# Del any extra keys to the language file
for key in miss:
del lang_data[key]
# Sort the keys of the language file to match the order of the standard file
lang_data = OrderedDict(
sorted(lang_data.items(), key=lambda x: list(standard_data.keys()).index(x[0]))
)
# Save the updated language file
with open(lang_file, "w", encoding="utf-8") as f:
json.dump(lang_data, f, ensure_ascii=False, indent=4)