2016-03-16 15:19:22 +00:00
|
|
|
#!/usr/bin/env python3
|
2016-02-25 13:53:53 +00:00
|
|
|
|
|
|
|
# Remove extra translations
|
|
|
|
|
|
|
|
import glob
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import re
|
|
|
|
from xml.etree import ElementTree
|
|
|
|
|
|
|
|
formatRe = re.compile(r'(%%|%[^%](\$.)?)')
|
|
|
|
|
2018-02-13 17:01:20 +01:00
|
|
|
simpleFormatRe = re.compile(r'%[ds]')
|
|
|
|
numberedFormatRe = re.compile(r'%[0-9]+\$')
|
2016-02-25 13:53:53 +00:00
|
|
|
validFormatRe = re.compile(r'^(%%|%[sd]|%[0-9]\$[sd])$')
|
2017-05-02 20:51:42 +02:00
|
|
|
oddQuotingRe = re.compile(r'^"\s*(.+?)\s*"$')
|
2016-02-25 13:53:53 +00:00
|
|
|
|
2017-05-10 11:12:48 +02:00
|
|
|
resdir = os.path.join(os.path.dirname(__file__), '..', 'app', 'src', 'main', 'res')
|
2017-05-02 20:50:01 +02:00
|
|
|
|
2016-02-25 13:53:53 +00:00
|
|
|
count = 0
|
|
|
|
|
2017-05-10 11:12:48 +02:00
|
|
|
for d in sorted(glob.glob(os.path.join(resdir, 'values-*'))):
|
2016-02-25 13:53:53 +00:00
|
|
|
|
|
|
|
str_path = os.path.join(d, 'strings.xml')
|
|
|
|
if not os.path.exists(str_path):
|
|
|
|
continue
|
|
|
|
|
2017-05-02 20:51:42 +02:00
|
|
|
with open(str_path, encoding='utf-8') as fp:
|
|
|
|
fulltext = fp.read()
|
|
|
|
|
2016-02-25 13:53:53 +00:00
|
|
|
tree = ElementTree.parse(str_path)
|
|
|
|
root = tree.getroot()
|
|
|
|
|
2017-04-12 10:03:58 +10:00
|
|
|
for e in root.findall('.//string') + root.findall('.//item'):
|
|
|
|
if e.tag == "item" and e.text is None:
|
|
|
|
continue
|
|
|
|
|
2018-02-13 17:01:20 +01:00
|
|
|
found_simple_format = False # %s
|
|
|
|
found_numbered_format = False # %1$s
|
2016-02-25 13:53:53 +00:00
|
|
|
for m in formatRe.finditer(e.text):
|
|
|
|
s = m.group(0)
|
2018-02-13 17:01:20 +01:00
|
|
|
if simpleFormatRe.match(s):
|
|
|
|
found_simple_format = True
|
|
|
|
if numberedFormatRe.match(s):
|
|
|
|
found_numbered_format = True
|
2016-02-25 13:53:53 +00:00
|
|
|
if validFormatRe.match(s):
|
|
|
|
continue
|
|
|
|
count += 1
|
|
|
|
print('%s: Invalid format "%s" in "%s"' % (str_path, s, e.text))
|
|
|
|
|
2018-02-13 17:01:20 +01:00
|
|
|
if found_simple_format and found_numbered_format:
|
|
|
|
count += 1
|
|
|
|
print('%s: Invalid mixed formats "%s" in "%s"' % (str_path, s, e.text))
|
|
|
|
|
2017-05-02 20:51:42 +02:00
|
|
|
m = oddQuotingRe.search(e.text)
|
|
|
|
if m:
|
|
|
|
print('%s: odd quoting in %s' % (str_path, e.tag))
|
|
|
|
print('found', fulltext.rfind(e.text))
|
|
|
|
fulltext = fulltext.replace(e.text, m.group(1))
|
|
|
|
count += 1
|
|
|
|
if e.text != m.group(1):
|
|
|
|
print(e.text, '-=<' + m.group(1) + '>=-')
|
|
|
|
|
|
|
|
with open(str_path, 'w', encoding='utf-8') as fp:
|
|
|
|
fp.write(fulltext)
|
|
|
|
|
2016-02-25 13:53:53 +00:00
|
|
|
if count > 0:
|
|
|
|
print("%d misformatted strings found!" % count)
|
|
|
|
sys.exit(1)
|
|
|
|
|