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'(%%|%[^%](\$.)?)')
|
|
|
|
|
|
|
|
validFormatRe = re.compile(r'^(%%|%[sd]|%[0-9]\$[sd])$')
|
|
|
|
|
2017-05-02 20:50:01 +02:00
|
|
|
projectdir = os.path.join(os.path.dirname(__file__), '..')
|
|
|
|
|
2016-02-25 13:53:53 +00:00
|
|
|
count = 0
|
|
|
|
|
2017-05-02 20:50:01 +02:00
|
|
|
for d in sorted(glob.glob(os.path.join(projectdir, 'src', 'main', 'res', '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
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2016-02-25 13:53:53 +00:00
|
|
|
for m in formatRe.finditer(e.text):
|
|
|
|
s = m.group(0)
|
|
|
|
if validFormatRe.match(s):
|
|
|
|
continue
|
|
|
|
count += 1
|
|
|
|
print('%s: Invalid format "%s" in "%s"' % (str_path, s, e.text))
|
|
|
|
|
|
|
|
if count > 0:
|
|
|
|
print("%d misformatted strings found!" % count)
|
|
|
|
sys.exit(1)
|
|
|
|
|