diff options
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) |
