1
0
Fork 0
mirror of https://github.com/YunoHost/apps.git synced 2024-09-03 20:06:07 +02:00

feat(translate_apps): use json.dumps the same way than weblate to avoid duplications

This commit is contained in:
Laurent Peuch 2024-03-31 06:44:12 +02:00 committed by OniriCorpe
parent 2e5a2bbfa0
commit a3b7509a74

View file

@ -84,12 +84,12 @@ def extract_strings_to_translate_from_apps(apps, translations_repository):
for language, translated_strings in translations.items():
translations_repository.write_file(
translations_path / f"{language}.json",
json.dumps(translated_strings, indent=4, sort_keys=True),
json.dumps(translated_strings, indent=4, sort_keys=True, ensure_ascii=False) + "\n",
)
else:
translations_repository.write_file(
translations_path / "en.json",
json.dumps(translations["en"], indent=4, sort_keys=True),
json.dumps(translations["en"], indent=4, sort_keys=True, ensure_ascii=False) + "\n",
)
# add strings that aren't already present but don't overwrite existing ones
@ -101,8 +101,9 @@ def extract_strings_to_translate_from_apps(apps, translations_repository):
if not (translations_path / f"{language}.json").exists():
translations_repository.write_file(
translations_path / f"{language}.json",
json.dumps(translated_strings, indent=4, sort_keys=True),
json.dumps(translated_strings, indent=4, sort_keys=True, ensure_ascii=False) + "\n",
)
else: # if it exists, only add keys that aren't already present
language_file = json.load((translations_path / f"{language}.json").open())
for key, translated_string in translated_strings.items():
@ -111,7 +112,7 @@ def extract_strings_to_translate_from_apps(apps, translations_repository):
translations_repository.write_file(
translations_path / f"{language}.json",
json.dumps(language_file, indent=4, sort_keys=True),
json.dumps(language_file, indent=4, sort_keys=True, ensure_ascii=False) + "\n",
)
# if something has been modified