sync up translation scripts to use the same code
To keep these scripts simple and readible, it makes sense to keep them as separate scripts. But they should use the same approach as much as possible.
This commit is contained in:
parent
082b6091fc
commit
3df626aed1
@ -13,11 +13,11 @@ formatRe = re.compile(r'(%%|%[^%](\$.)?)')
|
|||||||
validFormatRe = re.compile(r'^(%%|%[sd]|%[0-9]\$[sd])$')
|
validFormatRe = re.compile(r'^(%%|%[sd]|%[0-9]\$[sd])$')
|
||||||
oddQuotingRe = re.compile(r'^"\s*(.+?)\s*"$')
|
oddQuotingRe = re.compile(r'^"\s*(.+?)\s*"$')
|
||||||
|
|
||||||
projectdir = os.path.join(os.path.dirname(__file__), '..')
|
resdir = os.path.join(os.path.dirname(__file__), '..', 'app', 'src', 'main', 'res')
|
||||||
|
|
||||||
count = 0
|
count = 0
|
||||||
|
|
||||||
for d in sorted(glob.glob(os.path.join(projectdir, 'src', 'main', 'res', 'values-*'))):
|
for d in sorted(glob.glob(os.path.join(resdir, 'values-*'))):
|
||||||
|
|
||||||
str_path = os.path.join(d, 'strings.xml')
|
str_path = os.path.join(d, 'strings.xml')
|
||||||
if not os.path.exists(str_path):
|
if not os.path.exists(str_path):
|
||||||
|
@ -10,34 +10,35 @@ import re
|
|||||||
from xml.etree import ElementTree
|
from xml.etree import ElementTree
|
||||||
|
|
||||||
resdir = os.path.join(os.path.dirname(__file__), '..', 'app', 'src', 'main', 'res')
|
resdir = os.path.join(os.path.dirname(__file__), '..', 'app', 'src', 'main', 'res')
|
||||||
|
sourcepath = os.path.join(resdir, 'values', 'strings.xml')
|
||||||
|
|
||||||
strings = set()
|
strings = set()
|
||||||
|
for e in ElementTree.parse(sourcepath).getroot().findall('.//string'):
|
||||||
for e in ElementTree.parse(os.path.join(resdir, 'values', 'strings.xml')).getroot().findall('.//string'):
|
|
||||||
name = e.attrib['name']
|
name = e.attrib['name']
|
||||||
strings.add(name)
|
strings.add(name)
|
||||||
|
|
||||||
for d in glob.glob(os.path.join(resdir, 'values-*')):
|
for d in sorted(glob.glob(os.path.join(resdir, 'values-*'))):
|
||||||
|
|
||||||
str_path = os.path.join(d, 'strings.xml')
|
str_path = os.path.join(d, 'strings.xml')
|
||||||
if os.path.exists(str_path):
|
if not os.path.exists(str_path):
|
||||||
header = ''
|
continue
|
||||||
with open(str_path, 'r') as f:
|
|
||||||
header = f.readline()
|
|
||||||
tree = ElementTree.parse(str_path)
|
|
||||||
root = tree.getroot()
|
|
||||||
|
|
||||||
elems = root.findall('.//string')
|
header = ''
|
||||||
for e in elems:
|
with open(str_path, 'r') as f:
|
||||||
name = e.attrib['name']
|
header = f.readline()
|
||||||
if name not in strings:
|
tree = ElementTree.parse(str_path)
|
||||||
root.remove(e)
|
root = tree.getroot()
|
||||||
if not e.text:
|
|
||||||
root.remove(e)
|
|
||||||
|
|
||||||
result = re.sub(r' />', r'/>', ElementTree.tostring(root, encoding='utf-8').decode('utf-8'))
|
for e in root.findall('.//string'):
|
||||||
|
name = e.attrib['name']
|
||||||
|
if name not in strings:
|
||||||
|
root.remove(e)
|
||||||
|
if not e.text:
|
||||||
|
root.remove(e)
|
||||||
|
|
||||||
with open(str_path, 'w+') as f:
|
result = re.sub(r' />', r'/>', ElementTree.tostring(root, encoding='utf-8').decode('utf-8'))
|
||||||
f.write(header)
|
|
||||||
f.write(result)
|
with open(str_path, 'w+') as f:
|
||||||
f.write('\n')
|
f.write(header)
|
||||||
|
f.write(result)
|
||||||
|
f.write('\n')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user