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.
This commit is contained in:
Jules Aguillon
2024-02-05 17:36:43 +01:00
parent 82a9774f5a
commit 5ce89d1b4b
100 changed files with 197 additions and 15 deletions

View File

@@ -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)