From 5ce89d1b4b2ad5ebc7c48b1fb395f6bb3e9895bc Mon Sep 17 00:00:00 2001 From: Jules Aguillon Date: Mon, 5 Feb 2024 17:36:43 +0100 Subject: 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. --- sync_translations.py | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) (limited to 'sync_translations.py') 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) -- cgit v1.2.3