-
Notifications
You must be signed in to change notification settings - Fork 5
/
port_strings.py
68 lines (54 loc) · 1.95 KB
/
port_strings.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/python
import xml.etree.ElementTree as etree
import xml.dom.minidom as minidom
import glob
import os
import sys
def makedir(directory):
if not os.path.exists(directory):
os.makedirs(directory)
def findandappend(source, target):
nodes = source.findall(".//string[@multiapk='true']")
for node in nodes:
node.attrib.pop('multiapk')
target.append(node)
def indent(elem, level=0):
i = "\n" + level*"\t"
if len(elem):
if not elem.text or not elem.text.strip():
elem.text = i + "\t"
if not elem.tail or not elem.tail.strip():
elem.tail = i
for elem in elem:
indent(elem, level+1)
if not elem.tail or not elem.tail.strip():
elem.tail = i
else:
if level and (not elem.tail or not elem.tail.strip()):
elem.tail = i
def generatefile(sources, targets):
root = etree.Element('resources')
for source in sources:
findandappend(etree.parse(source), root)
indent(root)
output = etree.tostring(root)
for target in targets:
f = open(target, 'wb')
f.write(bytes('<?xml version="1.0" encoding="UTF-8"?>\n', 'utf-8'))
f.write(output)
f.close()
rootPath = sys.path[0] + '/'
resLibrary = rootPath + 'SMSFixLibrary/res/'
resRegular = rootPath + 'SMSFix/res/'
resDonate = rootPath + 'SMSFixDonate/res/'
valuesLibrary = resLibrary + 'values/'
valuesRegular = resRegular + 'values/'
valuesDonate = resDonate + 'values/'
# english (with universal file)
generatefile({valuesLibrary + "strings-universal.xml", valuesLibrary + "strings.xml"}, {valuesRegular + "strings.xml", valuesDonate + "strings.xml"})
# the rest
for directory in glob.glob(resLibrary + 'values-*'):
valuesDir = directory[len(resLibrary):]
makedir(resRegular + valuesDir)
makedir(resDonate + valuesDir)
generatefile({directory + '/strings.xml'}, {resRegular + valuesDir + '/strings.xml', resDonate + valuesDir + '/strings.xml'})