mirror of
https://github.com/Julow/Unexpected-Keyboard.git
synced 2025-06-14 22:08:05 +02:00
sync_translations.py: Output sub-elements
This commit is contained in:
parent
59b0b60f3f
commit
c4de1ec267
@ -9,27 +9,24 @@ import glob
|
|||||||
# The baseline is 'values/strings.xml', which is english.
|
# The baseline is 'values/strings.xml', which is english.
|
||||||
|
|
||||||
def parse_strings_file(file):
|
def parse_strings_file(file):
|
||||||
resources = ET.parse(file).getroot()
|
def key(ent): return ent.get("name"), ent.get("product")
|
||||||
return [
|
resrcs = ET.parse(file).getroot()
|
||||||
((ent.get("name"), ent.get("product")), ent.text)
|
return { key(ent): ent for ent in resrcs if ent.tag == "string" }
|
||||||
for ent in resources if ent.tag == "string"
|
|
||||||
]
|
|
||||||
|
|
||||||
def string_entry_str(name, text, product):
|
def dump_entry(out, entry, comment):
|
||||||
product_attr = ' product="%s"' % product if product != None else ""
|
out.write(" ")
|
||||||
text_encoded = saxutils.escape(text)
|
if comment: out.write("<!-- ")
|
||||||
return '<string name="%s"%s>%s</string>' % (name, product_attr, text_encoded)
|
out.write(ET.tostring(entry, "unicode").strip())
|
||||||
|
if comment: out.write(" -->")
|
||||||
|
out.write("\n")
|
||||||
|
|
||||||
def write_updated_strings(out, baseline, strings):
|
def write_updated_strings(out, baseline, strings):
|
||||||
out.write('<?xml version="1.0" encoding="utf-8"?>\n<resources>\n')
|
out.write('<?xml version="1.0" encoding="utf-8"?>\n<resources>\n')
|
||||||
for key, default_text in baseline:
|
for key, baseline_entry in baseline.items():
|
||||||
name, product = key
|
|
||||||
if key in strings:
|
if key in strings:
|
||||||
ent = string_entry_str(name, strings[key], product)
|
dump_entry(out, strings[key], False)
|
||||||
out.write(" %s\n" % ent)
|
|
||||||
else:
|
else:
|
||||||
def_ent = string_entry_str(name, default_text, product)
|
dump_entry(out, baseline_entry, True)
|
||||||
out.write(" <!-- %s -->\n" % def_ent)
|
|
||||||
out.write('</resources>\n')
|
out.write('</resources>\n')
|
||||||
|
|
||||||
baseline = parse_strings_file("res/values/strings.xml")
|
baseline = parse_strings_file("res/values/strings.xml")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user