use IDs rather than english strings as keys in passing

translations. Requires parallel change on client, and currently
doesn't quite work because e.g. \n is not replaced before the
translation is rendered.
This commit is contained in:
Eric House 2014-04-24 06:24:38 -07:00
parent 1e5a474692
commit 8612a5f624

View file

@ -1,6 +1,6 @@
#!/usr/bin/python
import re
import re, sys
from lxml import etree
@ -13,7 +13,30 @@ from lxml import etree
english = 'res/values/strings.xml'
other_f = 'res_src/values-%s/strings.xml'
def asMap( path ):
def readIDs(base):
ids = {}
start = re.compile('\s*public static final class string {\s*')
end = re.compile('\s*}\s*')
entry = re.compile('\s*public static final int (\S+)=(0x.*);\s*')
inLine = False
path = base + '/archive/R.java'
for line in open(path, 'r'):
line = line.strip()
# print line
if inLine:
if end.match(line):
break
else:
match = entry.match(line)
if match:
name = match.group(1)
value = int(match.group(2), 16)
ids[name] = value
elif start.match(line):
inLine = True
return ids
def asMap( path, ids ):
map = {}
parser = etree.XMLParser(remove_blank_text=True)
doc = etree.parse( path, parser )
@ -26,21 +49,25 @@ def asMap( path ):
.replace("\\'", "'") \
.replace( '\\"', '"' )
# print 'text after:', text
map[elem.get('name')] = text
name = elem.get('name')
id = ids[name]
map[id] = text
return map
def getXlationFor( base, loc ):
eng = asMap( base + '/' + english )
other = asMap( base + '/' + other_f % (loc) )
ids = readIDs(base)
eng = asMap( base + '/' + english, ids )
other = asMap( base + '/' + other_f % (loc), ids )
result = []
for key in eng.keys():
if key in other:
result.append( { 'en' : eng[key], 'loc' : other[key] } )
result.append( { 'id' : key, 'loc' : other[key] } )
return result
def main():
data = getXlationFor( 'ba_CK' )
data = getXlationFor( 'ca_PS' )
data = getXlationFor( '.', 'ba_CK' )
print data
data = getXlationFor( '.', 'ca_PS' )
print data
##############################################################################