BobStore/app/tools/remove-unused-trans.py
Hans-Christoph Steiner 3fcdfe85bb move main project files into standard gradle/Android Studio layout
This makes it a lot easier to setup all the testing stuff.  Mostly,
I'm tired of fighting Android Studio's fragility, so I want to remove
as much non-standardness as possible in the hopes of improving that
situation.

closes #534 https://gitlab.com/fdroid/fdroidclient/issues/534
2016-03-28 12:12:37 +02:00

40 lines
1.0 KiB
Python
Executable File

#!/usr/bin/env python3
# Remove extra translations
import glob
import os
import re
from xml.etree import ElementTree
strings = set()
for e in ElementTree.parse(os.path.join('src', 'main', 'res', 'values', 'strings.xml')).getroot().findall('.//string'):
name = e.attrib['name']
strings.add(name)
for d in glob.glob(os.path.join('res', 'values-*')):
str_path = os.path.join(d, 'strings.xml')
if os.path.exists(str_path):
header = ''
with open(str_path, 'r') as f:
header = f.readline()
tree = ElementTree.parse(str_path)
root = tree.getroot()
elems = root.findall('.//string')
for e in elems:
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')