generate menu resources from the old files, adding the 'loc:' key for those title strings listed in strings.xml

This commit is contained in:
Eric House 2014-04-07 08:14:09 -07:00
parent 96194671e2
commit aad4872f68
3 changed files with 44 additions and 0 deletions

View file

@ -102,6 +102,11 @@
failonerror="true" output="/dev/null"
/>
<exec dir="." executable="../scripts/mk_xml.py"
failonerror="true" output="/dev/null"
>
</exec>
<exec dir="." executable="../scripts/gen_gcmid.sh"
output="src/org/eehouse/android/xw4bt/GCMConsts.java"
failonerror="true" logError="true"

View file

@ -0,0 +1,6 @@
/board_menu.xml
/chat_menu.xml
/dicts_menu.xml
/games_list_menu.xml
/loc_menu.xml
/studylist.xml

View file

@ -0,0 +1,33 @@
#!/usr/bin/python
import glob, sys, re, os
from lxml import etree
pairs = {}
STR_REF = re.compile('@string/(.*)$')
def xform(src, dest):
doc = etree.parse(src)
for item in doc.findall('item'):
title = item.get('{http://schemas.android.com/apk/res/android}title')
if title:
match = STR_REF.match(title)
if match:
key = match.group(1)
if key in pairs:
print key, "loc:" + key
item.set('{http://schemas.android.com/apk/res/android}title', "loc:" + key)
doc.write( dest, pretty_print=True )
# Gather all localizable strings
for path in glob.iglob( "res/values/strings.xml" ):
for action, elem in etree.iterparse(path):
if "end" == action and 'string' == elem.tag:
pairs[elem.get('name')] = True
for subdir, dirs, files in os.walk('res_src'):
for file in files:
src = subdir + '/' + file
dest = src.replace( 'res_src', 'res', 1 )
xform( src, dest )