2023-04-12 04:48:39 +02:00
|
|
|
import json
|
2023-04-16 08:29:01 +02:00
|
|
|
import os
|
2023-04-12 04:48:39 +02:00
|
|
|
from collections import OrderedDict
|
|
|
|
|
|
|
|
# Define the standard file name
|
|
|
|
standard_file = "zh_CN.json"
|
|
|
|
|
2023-04-16 08:29:01 +02:00
|
|
|
# Find all JSON files in the directory
|
|
|
|
dir_path = "./"
|
2023-04-16 11:30:32 +02:00
|
|
|
languages = [
|
|
|
|
f for f in os.listdir(dir_path) if f.endswith(".json") and f != standard_file
|
|
|
|
]
|
2023-04-12 04:48:39 +02:00
|
|
|
|
|
|
|
# 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())
|
|
|
|
|
2023-04-12 10:53:50 +02:00
|
|
|
miss = set(lang_data.keys()) - set(standard_data.keys())
|
|
|
|
|
2023-04-12 04:48:39 +02:00
|
|
|
# Add any missing keys to the language file
|
|
|
|
for key in diff:
|
|
|
|
lang_data[key] = key
|
|
|
|
|
2023-04-12 10:53:50 +02:00
|
|
|
# Del any extra keys to the language file
|
|
|
|
for key in miss:
|
|
|
|
del lang_data[key]
|
|
|
|
|
2023-04-12 04:48:39 +02:00
|
|
|
# Sort the keys of the language file to match the order of the standard file
|
2023-04-15 13:44:24 +02:00
|
|
|
lang_data = OrderedDict(
|
|
|
|
sorted(lang_data.items(), key=lambda x: list(standard_data.keys()).index(x[0]))
|
2023-04-16 11:30:32 +02:00
|
|
|
)
|
2023-04-12 04:48:39 +02:00
|
|
|
|
|
|
|
# Save the updated language file
|
|
|
|
with open(lang_file, "w", encoding="utf-8") as f:
|
2023-04-16 11:30:32 +02:00
|
|
|
json.dump(lang_data, f, ensure_ascii=False, indent=4)
|
2023-04-17 14:49:29 +02:00
|
|
|
f.write("\n")
|