translation work 🗣

This commit is contained in:
Jokob-sk
2024-02-11 09:28:37 +11:00
parent 10f93d40ff
commit 001cb38924
6 changed files with 1717 additions and 1719 deletions

View File

@@ -1,5 +1,6 @@
import json
import os
import sys
def merge_translations(main_file, other_files):
# Load main file
@@ -7,10 +8,10 @@ def merge_translations(main_file, other_files):
main_data = json.load(f)
# Get keys and sort them alphabetically
keys = sorted(main_data['en_us'].keys())
keys = sorted(main_data.keys())
# Sort the keys alphabetically in the main file
main_data['en_us'] = {k: main_data['en_us'][k] for k in sorted(main_data['en_us'].keys())}
main_data = {k: main_data[k] for k in keys}
# Rewrite sorted main file
with open(main_file, 'w') as f:
@@ -21,15 +22,16 @@ def merge_translations(main_file, other_files):
with open(file_name, 'r+') as f:
data = json.load(f)
for key in keys:
if key not in data[file_name.split('.')[0]]:
data[file_name.split('.')[0]][key] = ""
if key not in data:
data[key] = ""
# Sort the keys alphabetically for each language
data[file_name.split('.')[0]] = {k: data[file_name.split('.')[0]][k] for k in sorted(data[file_name.split('.')[0]].keys())}
data = {k: data[k] for k in sorted(data.keys())}
f.seek(0)
json.dump(data, f, indent=4)
f.truncate()
if __name__ == "__main__":
main_file = "en_us.json"
other_files = ["de_de.json", "es_es.json", "fr_fr.json", "nb_no.json"]
merge_translations(main_file, other_files)
current_path = os.path.dirname(os.path.abspath(__file__))
json_files = ["en_us.json", "de_de.json", "es_es.json", "fr_fr.json", "nb_no.json"]
file_paths = [os.path.join(current_path, file) for file in json_files]
merge_translations(file_paths[0], file_paths[1:])