chiark / gitweb /
Added 'fixtrans' build option
authorCiaran Gultnieks <ciaran@ciarang.com>
Tue, 1 Feb 2011 14:54:34 +0000 (14:54 +0000)
committerCiaran Gultnieks <ciaran@ciarang.com>
Tue, 1 Feb 2011 14:54:34 +0000 (14:54 +0000)
README
build.py

diff --git a/README b/README
index f6adb6ba1c51dc82cb67227b1786c29e2f29b89e..40e4353c1f17cf14b6ebcd1ef66dcf16b2a519e6 100644 (file)
--- 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:
 
index 07daa977dc44afefcf4bd58ef2bcdd5946a7a1b6..248bb7f9d92f948251c797a62f1dedac238e9bcf 100644 (file)
--- 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)