Clicko777/RVC_HFv2
0
1import json2import os3from collections import OrderedDict4 5# Define the standard file name6standard_file = "en_US.json"7 8# Find all JSON files in the directory9dir_path = "./"10languages = [11 f for f in os.listdir(dir_path) if f.endswith(".json") and f != standard_file12]13 14# Load the standard file15with open(standard_file, "r", encoding="utf-8") as f:16 standard_data = json.load(f, object_pairs_hook=OrderedDict)17 18# Loop through each language file19for lang_file in languages:20 # Load the language file21 with open(lang_file, "r", encoding="utf-8") as f:22 lang_data = json.load(f, object_pairs_hook=OrderedDict)23 24 # Find the difference between the language file and the standard file25 diff = set(standard_data.keys()) - set(lang_data.keys())26 27 miss = set(lang_data.keys()) - set(standard_data.keys())28 29 # Add any missing keys to the language file30 for key in diff:31 lang_data[key] = key32 33 # Del any extra keys to the language file34 for key in miss:35 del lang_data[key]36 37 # Sort the keys of the language file to match the order of the standard file38 lang_data = OrderedDict(39 sorted(lang_data.items(), key=lambda x: list(standard_data.keys()).index(x[0]))40 )41 42 # Save the updated language file43 with open(lang_file, "w", encoding="utf-8") as f:44 json.dump(lang_data, f, ensure_ascii=False, indent=4)45 f.write("\n")46 