mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-20 22:26:54 +01:00
tweaks to strings.xml copying: add comment warning files are
generated, and don't copy over strings that say "XLATE ME"
This commit is contained in:
parent
9ee5c0d0eb
commit
10fe016785
2 changed files with 87 additions and 8 deletions
|
@ -686,6 +686,31 @@ public final class R {
|
|||
############################################################
|
||||
|
||||
Text of menuitem in main games-list screen's menu
|
||||
|
||||
DO NOT EDIT THIS FILE!!!!
|
||||
It was generated (from res_src/values-ca/strings.xml).
|
||||
Any changes you make to it will be lost.
|
||||
|
||||
|
||||
DO NOT EDIT THIS FILE!!!!
|
||||
It was generated (from res_src/values-cs/strings.xml).
|
||||
Any changes you make to it will be lost.
|
||||
|
||||
|
||||
DO NOT EDIT THIS FILE!!!!
|
||||
It was generated (from res_src/values-fr/strings.xml).
|
||||
Any changes you make to it will be lost.
|
||||
|
||||
|
||||
DO NOT EDIT THIS FILE!!!!
|
||||
It was generated (from res_src/values-pt/strings.xml).
|
||||
Any changes you make to it will be lost.
|
||||
|
||||
|
||||
DO NOT EDIT THIS FILE!!!!
|
||||
It was generated (from res_src/values-sk/strings.xml).
|
||||
Any changes you make to it will be lost.
|
||||
|
||||
*/
|
||||
public static final int button_new_game=0x7f05007b;
|
||||
/** Games list screen menuitem text for creating a new group
|
||||
|
|
|
@ -8,7 +8,36 @@
|
|||
import re, sys, os, getopt
|
||||
from lxml import etree
|
||||
|
||||
def checkAndCopy( engNames, src, dest ):
|
||||
s_prefix = 'XLATE ME: '
|
||||
|
||||
|
||||
sComment = """
|
||||
DO NOT EDIT THIS FILE!!!!
|
||||
It was generated (from %s).
|
||||
Any changes you make to it will be lost.
|
||||
"""
|
||||
|
||||
def sameOrSameWithPrefix( str1, str2 ):
|
||||
result = str1 == str2
|
||||
if not result:
|
||||
if str1.startswith(s_prefix):
|
||||
result = str1[len(s_prefix):] == str2
|
||||
return result
|
||||
|
||||
def sameAsEnglishPlural(engNames, strElem):
|
||||
strs = engNames[strElem.get('name')]['strings']
|
||||
str = strElem.text
|
||||
result = 1 == len(strs) and 'other' in strs \
|
||||
and sameOrSameWithPrefix( str, strs['other'] )
|
||||
return result
|
||||
|
||||
def loadPlural(plural):
|
||||
items = {}
|
||||
for child in plural.getchildren():
|
||||
items[child.get('quantity')] = child.text
|
||||
return items
|
||||
|
||||
def checkAndCopy( engNames, src, dest, verbose ):
|
||||
parser = etree.XMLParser(remove_blank_text=True, encoding="utf-8")
|
||||
doc = etree.parse(src, parser)
|
||||
for elem in doc.getroot().iter():
|
||||
|
@ -18,13 +47,29 @@ def checkAndCopy( engNames, src, dest ):
|
|||
pass
|
||||
elif 'string' == elem.tag:
|
||||
name = elem.get('name')
|
||||
if not name in engNames or not 'string' == engNames[name]:
|
||||
print 'removing', name
|
||||
if not name in engNames or elem.text.startswith(s_prefix):
|
||||
elem.getparent().remove( elem )
|
||||
elif not 'string' == engNames[name]['type']:
|
||||
if 'plurals' == engNames[name]['type']:
|
||||
if sameAsEnglishPlural( engNames, elem ):
|
||||
elem.getparent().remove( elem )
|
||||
else:
|
||||
elem.tag = 'plurals'
|
||||
item = etree.Element("item")
|
||||
item.text = elem.text
|
||||
elem.text = None
|
||||
item.set('quantity', 'other')
|
||||
elem.append( item )
|
||||
if verbose: print 'translated string', name, 'to plural'
|
||||
else:
|
||||
elem.getparent().remove( elem )
|
||||
elif engNames[name]['string'] == elem.text:
|
||||
if verbose: print "Same as english: name: %s; text: %s" % (name, elem.text)
|
||||
elem.getparent().remove( elem )
|
||||
elif 'plurals' == elem.tag:
|
||||
name = elem.get('name')
|
||||
if not name in engNames or not 'plurals' == engNames[name]:
|
||||
print 'removing', name
|
||||
if not name in engNames or not 'plurals' == engNames[name]['type']:
|
||||
# print 'removing', name
|
||||
elem.getparent().remove( elem )
|
||||
elif not isinstance( elem.tag, basestring ): # comment
|
||||
elem.getparent().remove(elem)
|
||||
|
@ -33,6 +78,8 @@ def checkAndCopy( engNames, src, dest ):
|
|||
sys.exit(1)
|
||||
|
||||
if True:
|
||||
comment = etree.Comment(sComment % (src))
|
||||
doc.getroot().insert( 0, comment )
|
||||
dir = os.path.dirname( dest )
|
||||
try: os.makedirs( dir )
|
||||
except: pass
|
||||
|
@ -42,6 +89,7 @@ def checkAndCopy( engNames, src, dest ):
|
|||
def main():
|
||||
# add these via params later
|
||||
excepts = ['values-ca_PS', 'values-ba_CK']
|
||||
verboses = ['values-fr']
|
||||
|
||||
# summarize the english file
|
||||
wd = os.path.dirname(sys.argv[0])
|
||||
|
@ -55,8 +103,12 @@ def main():
|
|||
for typ in ['string', 'plurals']:
|
||||
for elem in doc.findall(typ):
|
||||
name = elem.get('name')
|
||||
engNames[name] = typ
|
||||
|
||||
item = { 'type' : typ }
|
||||
if typ == 'string':
|
||||
item['string'] = elem.text
|
||||
else:
|
||||
item['strings'] = loadPlural(elem)
|
||||
engNames[name] = item
|
||||
# print engNames
|
||||
|
||||
# iterate over src files
|
||||
|
@ -68,8 +120,10 @@ def main():
|
|||
path = None
|
||||
break
|
||||
if path:
|
||||
verbose = 0 < len([verb for verb in verboses if verb in path])
|
||||
print "*** looking at %s ***" % (path)
|
||||
dest = path.replace( 'res_src', 'res', 1 )
|
||||
checkAndCopy( engNames, path, dest )
|
||||
checkAndCopy( engNames, path, dest, verbose )
|
||||
|
||||
##############################################################################
|
||||
if __name__ == '__main__':
|
||||
|
|
Loading…
Reference in a new issue