2016-02-25 13:39:39 +00:00
|
|
|
#!/usr/bin/env python3
|
2015-03-08 20:25:27 +01:00
|
|
|
|
2017-05-10 11:01:50 +02:00
|
|
|
# This script removes strings from the translated files that are not useful:
|
|
|
|
# * translations for strings that are no longer used
|
|
|
|
# * empty translated strings, English is better than no text at all
|
2015-03-08 20:25:27 +01:00
|
|
|
|
|
|
|
import glob
|
|
|
|
import os
|
|
|
|
import re
|
|
|
|
from xml.etree import ElementTree
|
|
|
|
|
2017-05-10 11:01:50 +02:00
|
|
|
resdir = os.path.join(os.path.dirname(__file__), '..', 'app', 'src', 'main', 'res')
|
2017-05-10 11:12:48 +02:00
|
|
|
sourcepath = os.path.join(resdir, 'values', 'strings.xml')
|
2017-05-10 11:01:50 +02:00
|
|
|
|
2015-03-08 20:25:27 +01:00
|
|
|
strings = set()
|
2017-05-10 11:12:48 +02:00
|
|
|
for e in ElementTree.parse(sourcepath).getroot().findall('.//string'):
|
2015-03-08 20:25:27 +01:00
|
|
|
name = e.attrib['name']
|
|
|
|
strings.add(name)
|
|
|
|
|
2017-05-10 11:12:48 +02:00
|
|
|
for d in sorted(glob.glob(os.path.join(resdir, 'values-*'))):
|
2015-03-08 20:25:27 +01:00
|
|
|
|
|
|
|
str_path = os.path.join(d, 'strings.xml')
|
2017-05-10 11:12:48 +02:00
|
|
|
if not os.path.exists(str_path):
|
|
|
|
continue
|
|
|
|
|
|
|
|
header = ''
|
|
|
|
with open(str_path, 'r') as f:
|
|
|
|
header = f.readline()
|
|
|
|
tree = ElementTree.parse(str_path)
|
|
|
|
root = tree.getroot()
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
result = re.sub(r' />', r'/>', ElementTree.tostring(root, encoding='utf-8').decode('utf-8'))
|
|
|
|
|
|
|
|
with open(str_path, 'w+') as f:
|
|
|
|
f.write(header)
|
|
|
|
f.write(result)
|
|
|
|
f.write('\n')
|