From d45efbddadf349c853f9295c00bfd8952dfedcd9 Mon Sep 17 00:00:00 2001 From: Ciaran Gultnieks Date: Tue, 1 Feb 2011 14:54:34 +0000 Subject: [PATCH] Added 'fixtrans' build option --- README | 5 +++++ build.py | 41 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/README b/README index f6adb6ba..40e4353c 100644 --- a/README +++ b/README @@ -176,6 +176,11 @@ configuration to the build. These are: are correct by looking at the build output - assume the metadata is correct. This takes away a useful level of sanity checking, and should only be used if the values can't be extracted. + fixtrans=yes Modifies any instances of string resources that use multiple + formatting arguments, but don't use positional notation. For + example, "Hello %s, %d" becomes "Hello %1$s, %2$d". Newer versions + of the Android platform tools enforce this sensible standard. If you + get error messages relating to that, you need to enable this. Another example, using extra parameters: diff --git a/build.py b/build.py index 07daa977..248bb7f9 100644 --- a/build.py +++ b/build.py @@ -247,6 +247,45 @@ for app in apps: if thisbuild.has_key('rm'): os.remove(os.path.join(build_dir, thisbuild['rm'])) + # Fix translation files if necessary... + if thisbuild.has_key('fixtrans') and thisbuild['fixtrans'] == 'yes': + for root, dirs, files in os.walk(os.path.join(root_dir,'res')): + for filename in files: + if filename.endswith('.xml'): + f = open(os.path.join(root, filename)) + changed = False + outlines = [] + for line in f: + num = 1 + index = 0 + oldline = line + while True: + index = line.find("%", index) + if index == -1: + break + next = line[index+1:index+2] + if next == "s" or next == "d": + line = (line[:index+1] + + str(num) + "$" + + line[index+1:]) + num += 1 + index += 3 + else: + index += 1 + # We only want to insert the positional arguments + # when there is more than one argument... + if oldline != line: + if num > 2: + changed = True + else: + line = oldline + outlines.append(line) + f.close() + if changed: + f = open(os.path.join(root, filename), 'w') + f.writelines(outlines) + f.close() + # Run a pre-build command if one is required... if thisbuild.has_key('prebuild'): if subprocess.call(thisbuild['prebuild'], @@ -409,7 +448,7 @@ for app in apps: vercode = re.match(pat, line).group(1) pat = re.compile(".*versionName='([^']*)'.*") version = re.match(pat, line).group(1) - if version == None or versioncode == None: + if version == None or vercode == None: print "Could not find version information in build in output" sys.exit(1) -- 2.30.2