diff options
| author | Jules Aguillon | 2024-02-05 17:36:43 +0100 |
|---|---|---|
| committer | Jules Aguillon | 2024-02-06 23:11:14 +0100 |
| commit | 5ce89d1b4b2ad5ebc7c48b1fb395f6bb3e9895bc (patch) | |
| tree | 7c6dc5d68736704820b260383b2d9202c909ec15 /sync_translations.py | |
| parent | 82a9774f5a2860854608a97db507abe322a68f99 (diff) | |
| download | unexpected-keyboard-5ce89d1b4b2ad5ebc7c48b1fb395f6bb3e9895bc.tar.gz unexpected-keyboard-5ce89d1b4b2ad5ebc7c48b1fb395f6bb3e9895bc.zip | |
Move store descriptions into strings files
This makes translation easier as there's a single file to edit at.
Existing short and full descriptions are conserved.
sync_translations.py takes care of updating the metadata files.
The metadata directories are renamed to match the language codes used in `res/`.
Contributing guidelines are updated accordingly.
Diffstat (limited to 'sync_translations.py')
| -rw-r--r-- | sync_translations.py | 34 |
1 files changed, 28 insertions, 6 deletions
diff --git a/sync_translations.py b/sync_translations.py index de0f16e..ec696c9 100644 --- a/sync_translations.py +++ b/sync_translations.py @@ -1,5 +1,5 @@ import xml.etree.ElementTree as ET -import glob +import glob, os # Edit every strings.xml files: # - Add missing translation as comments @@ -38,10 +38,32 @@ def sync(baseline, strings): (key, base_string, True) for key, base_string in baseline.items() ] +def sync_metadata(locale, strings): + meta_dir = "metadata/android/" + locale + def sync_meta_file(fname, string_name): + if string_name in strings: + string = strings[string_name] + if not os.path.isdir(meta_dir): + os.makedirs(meta_dir) + txt_file = os.path.join(meta_dir, fname) + with open(txt_file, "w", encoding="utf-8") as out: + out.write(string.text.removeprefix('"').removesuffix('"')) + out.write("\n") + sync_meta_file("title.txt", ("app_name_release", None)) + sync_meta_file("short_description.txt", ("short_description", None)) + sync_meta_file("full_description.txt", ("store_description", None)) + baseline = parse_strings_file("res/values/strings.xml") -for strings_file in glob.glob("res/values-*/strings.xml"): - strings = sync(baseline, dict(parse_strings_file(strings_file))) - with open(strings_file, "w", encoding="utf-8") as out: - write_updated_strings(out, strings) - print_status(strings_file, strings) +for value_dir in glob.glob("res/values-*"): + strings_file = os.path.join(value_dir, "strings.xml") + if os.path.isfile(strings_file): + local_strings = dict(parse_strings_file(strings_file)) + synced_strings = sync(baseline, local_strings) + with open(strings_file, "w", encoding="utf-8") as out: + write_updated_strings(out, synced_strings) + locale = os.path.basename(value_dir).removeprefix("values-") + sync_metadata(locale, local_strings) + print_status(strings_file, synced_strings) + +sync_metadata("en", baseline) |
