mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2024-12-30 10:26:58 +01:00
script to produce the translation array that's downloaded to device
This commit is contained in:
parent
0bf8b45157
commit
45b1b0bfa8
1 changed files with 44 additions and 0 deletions
44
xwords4/android/scripts/mk_for_download.py
Executable file
44
xwords4/android/scripts/mk_for_download.py
Executable file
|
@ -0,0 +1,44 @@
|
||||||
|
#!/usr/bin/python
|
||||||
|
|
||||||
|
import re
|
||||||
|
from lxml import etree
|
||||||
|
|
||||||
|
|
||||||
|
# Take an English strings.xml file and another, "join" them on the
|
||||||
|
# name of each string, and then produce an array that's a mapping of
|
||||||
|
# English to the other. Get ride of extra whitespace etc in the
|
||||||
|
# English strings so they're identical to how an Android app displays
|
||||||
|
# them.
|
||||||
|
|
||||||
|
english = 'res/values/strings.xml'
|
||||||
|
other_f = 'res_src/values-%s/strings.xml'
|
||||||
|
|
||||||
|
def asMap( path ):
|
||||||
|
map = {}
|
||||||
|
parser = etree.XMLParser(remove_blank_text=True)
|
||||||
|
doc = etree.parse( path, parser )
|
||||||
|
for elem in doc.getroot().iter():
|
||||||
|
if 'string' == elem.tag:
|
||||||
|
text = elem.text
|
||||||
|
if text:
|
||||||
|
text = " ".join(re.split('\s+', text)).replace('"', '\"')
|
||||||
|
map[elem.get('name')] = text
|
||||||
|
return map
|
||||||
|
|
||||||
|
def getXlationFor( loc ):
|
||||||
|
eng = asMap( english )
|
||||||
|
other = asMap( other_f % (loc) )
|
||||||
|
result = []
|
||||||
|
for key in eng.keys():
|
||||||
|
if key in other:
|
||||||
|
result.append( { 'en' : eng[key], 'loc' : other[key] } )
|
||||||
|
return result
|
||||||
|
|
||||||
|
def main():
|
||||||
|
data = getXlationFor( 'ba_CK' )
|
||||||
|
data = getXlationFor( 'ca_PS' )
|
||||||
|
print data
|
||||||
|
|
||||||
|
##############################################################################
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
Loading…
Reference in a new issue