mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-16 15:41:16 +01:00
script to generate fake locales from English strings.xml for use testing downloading translations
This commit is contained in:
parent
155dd6f19a
commit
5d3beb6404
1 changed files with 74 additions and 0 deletions
74
xwords4/android/scripts/fake_locales.py
Executable file
74
xwords4/android/scripts/fake_locales.py
Executable file
|
@ -0,0 +1,74 @@
|
||||||
|
#!/usr/bin/python
|
||||||
|
|
||||||
|
import sys, getopt, re
|
||||||
|
from lxml import etree
|
||||||
|
|
||||||
|
FMT = re.compile('.*%\d\$[dsXx].*', re.DOTALL)
|
||||||
|
FMT = re.compile('(%\d\$[dsXx])', re.DOTALL)
|
||||||
|
|
||||||
|
def capitalize( str ):
|
||||||
|
split = re.split( FMT, str )
|
||||||
|
for ii in range(len(split)):
|
||||||
|
part = split[ii]
|
||||||
|
if not re.match( FMT, part ):
|
||||||
|
split[ii] = split[ii].upper()
|
||||||
|
result = ''.join(split)
|
||||||
|
print str, '=>', result
|
||||||
|
return result;
|
||||||
|
|
||||||
|
def reverse( str ):
|
||||||
|
return str
|
||||||
|
|
||||||
|
def usage():
|
||||||
|
print "usage:", sys.argv[0], '-l ca_PS|ba_CK [-o outfile]'
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
def main():
|
||||||
|
print 'main'
|
||||||
|
algo = None
|
||||||
|
outfile = None
|
||||||
|
try:
|
||||||
|
pairs, rest = getopt.getopt(sys.argv[1:], "l:o:")
|
||||||
|
for option, value in pairs:
|
||||||
|
if option == '-l': algo = value
|
||||||
|
elif option == '-o': outfile = value
|
||||||
|
else:
|
||||||
|
print 'WTF'
|
||||||
|
usage()
|
||||||
|
except:
|
||||||
|
print 'got except'
|
||||||
|
print "Unexpected error:", sys.exc_info()[0]
|
||||||
|
usage()
|
||||||
|
|
||||||
|
print 'here'
|
||||||
|
|
||||||
|
if not algo:
|
||||||
|
print "no algo"
|
||||||
|
usage()
|
||||||
|
|
||||||
|
print 'here 2'
|
||||||
|
|
||||||
|
if algo == 'ca_PS':
|
||||||
|
func = capitalize
|
||||||
|
elif algo == 'ba_CK':
|
||||||
|
func = reverse
|
||||||
|
else:
|
||||||
|
print "no algo"
|
||||||
|
usage()
|
||||||
|
|
||||||
|
parser = etree.XMLParser(remove_blank_text=True)
|
||||||
|
doc = etree.parse("res/values/strings.xml", parser)
|
||||||
|
for elem in doc.getroot().iter():
|
||||||
|
if 'string' == elem.tag:
|
||||||
|
text = elem.text
|
||||||
|
if text:
|
||||||
|
elem.text = func(text)
|
||||||
|
|
||||||
|
if outfile:
|
||||||
|
out = open( outfile, "w" )
|
||||||
|
out.write( etree.tostring( doc, pretty_print=True, encoding="utf-8", xml_declaration=True ) )
|
||||||
|
|
||||||
|
##############################################################################
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
|
|
Loading…
Reference in a new issue