diff options
author | Android Chromium Automerger <chromium-automerger@android> | 2014-04-23 03:19:48 +0000 |
---|---|---|
committer | Android Chromium Automerger <chromium-automerger@android> | 2014-04-23 03:19:48 +0000 |
commit | 580c77c7d904292680ff46f4578f4aa337337154 (patch) | |
tree | 3c2b21bbe84540a8847af81acb8916d1ec0557ac | |
parent | fc300288d9f8b8f795aa8131cd0ab5f4cec154a4 (diff) | |
parent | 1370f19146300b010e054e20bd733e183ba6f30e (diff) | |
download | grit-580c77c7d904292680ff46f4578f4aa337337154.tar.gz |
Merge tools/grit from https://chromium.googlesource.com/external/grit-i18n.git at 1370f19146300b010e054e20bd733e183ba6f30e
This commit was generated by merge_from_chromium.py.
Change-Id: Ia56769ac66ccda381d9876a4bcd5da3b941935ef
-rw-r--r-- | grit/format/chrome_messages_json.py | 3 | ||||
-rw-r--r-- | grit/format/chrome_messages_json_unittest.py | 14 | ||||
-rwxr-xr-x | grit/format/data_pack.py | 8 | ||||
-rw-r--r-- | grit/node/io.py | 13 | ||||
-rw-r--r-- | grit/node/io_unittest.py | 16 | ||||
-rw-r--r-- | grit/testdata/generated_resources_iw.xtb | 4 | ||||
-rw-r--r-- | grit/testdata/generated_resources_no.xtb | 4 |
7 files changed, 53 insertions, 9 deletions
diff --git a/grit/format/chrome_messages_json.py b/grit/format/chrome_messages_json.py index b5af6d4..be934ab 100644 --- a/grit/format/chrome_messages_json.py +++ b/grit/format/chrome_messages_json.py @@ -28,7 +28,8 @@ def Format(root, lang='en', output_dir='.'): if id.startswith('IDR_') or id.startswith('IDS_'): id = id[4:] - loc_message = encoder.encode(child.Translate(lang)) + loc_message = encoder.encode(child.ws_at_start + child.Translate(lang) + + child.ws_at_end) if not first: yield ',\n' diff --git a/grit/format/chrome_messages_json_unittest.py b/grit/format/chrome_messages_json_unittest.py index 3dab23e..373751e 100644 --- a/grit/format/chrome_messages_json_unittest.py +++ b/grit/format/chrome_messages_json_unittest.py @@ -35,6 +35,12 @@ class ChromeMessagesJsonFormatUnittest(unittest.TestCase): <message name="IDS_STARTS_WITH_SPACE"> ''' (<ph name="COUNT">%d<ex>2</ex></ph>) </message> + <message name="IDS_ENDS_WITH_SPACE"> + (<ph name="COUNT">%d<ex>2</ex></ph>) ''' + </message> + <message name="IDS_SPACE_AT_BOTH_ENDS"> + ''' (<ph name="COUNT">%d<ex>2</ex></ph>) ''' + </message> <message name="IDS_DOUBLE_QUOTES"> A "double quoted" message. </message> @@ -59,7 +65,13 @@ class ChromeMessagesJsonFormatUnittest(unittest.TestCase): "message": "%1$d error, %2$d warning" }, "STARTS_WITH_SPACE": { - "message": "(%d)" + "message": " (%d)" + }, + "ENDS_WITH_SPACE": { + "message": "(%d) " + }, + "SPACE_AT_BOTH_ENDS": { + "message": " (%d) " }, "DOUBLE_QUOTES": { "message": "A \\"double quoted\\" message." diff --git a/grit/format/data_pack.py b/grit/format/data_pack.py index 779a862..02616c3 100755 --- a/grit/format/data_pack.py +++ b/grit/format/data_pack.py @@ -127,7 +127,7 @@ def RePack(output_file, input_files, whitelist_file=None): whitelist = None if whitelist_file: whitelist = util.ReadFile(whitelist_file, util.RAW_TEXT).strip().split('\n') - whitelist = map(int, whitelist) + whitelist = set(map(int, whitelist)) resources, encoding = RePackFromDataPackStrings(input_data_packs, whitelist) WriteDataPack(resources, output_file, encoding) @@ -137,7 +137,7 @@ def RePackFromDataPackStrings(inputs, whitelist): Args: inputs: a list of data pack strings that need to be combined. - whitelist: a list of resource IDs that should be kep in the output string + whitelist: a list of resource IDs that should be kept in the output string or None to include all resources. Returns: @@ -168,6 +168,10 @@ def RePackFromDataPackStrings(inputs, whitelist): for key in content.resources.keys() if key in whitelist]) resources.update(whitelisted_resources) + removed_keys = [key for key in content.resources.keys() + if key not in whitelist] + for key in removed_keys: + print 'RePackFromDataPackStrings Removed Key:', key else: resources.update(content.resources) diff --git a/grit/node/io.py b/grit/node/io.py index 1e590c5..9962bff 100644 --- a/grit/node/io.py +++ b/grit/node/io.py @@ -52,12 +52,15 @@ class FileNode(base.Node): except: print "Exception during parsing of %s" % self.GetInputPath() raise - # We special case 'he' and 'iw' because the translation console uses 'iw' - # and we use 'he'. + # Translation console uses non-standard language codes 'iw' and 'no' for + # Hebrew and Norwegian Bokmal instead of 'he' and 'nb' used in Chrome. + # Note that some Chrome's .grd still use 'no' instead of 'nb', but 'nb' is + # always used for generated .pak files. + ALTERNATIVE_LANG_CODE_MAP = { 'he': 'iw', 'nb': 'no' } assert (lang == self.attrs['lang'] or - (lang == 'iw' and self.attrs['lang'] == 'he')), ('The XTB file you ' - 'reference must contain messages in the language specified\n' - 'by the \'lang\' attribute.') + lang == ALTERNATIVE_LANG_CODE_MAP[self.attrs['lang']]), ( + 'The XTB file you reference must contain messages in the language ' + 'specified\nby the \'lang\' attribute.') def GetInputPath(self): return os.path.expandvars(self.attrs['path']) diff --git a/grit/node/io_unittest.py b/grit/node/io_unittest.py index 07298d7..7409b67 100644 --- a/grit/node/io_unittest.py +++ b/grit/node/io_unittest.py @@ -146,6 +146,22 @@ class FileNodeUnittest(unittest.TestCase): self.failUnless(outputs[2] not in active) self.failUnless(outputs[2].GetType() == 'rc_all') + # Verify that 'iw' and 'no' language codes in xtb files are mapped to 'he' and + # 'nb'. + def testLangCodeMapping(self): + grd = grd_reader.Parse(StringIO.StringIO('''<?xml version="1.0" encoding="UTF-8"?> + <grit latest_public_release="2" source_lang_id="en-US" current_release="3" base_dir="."> + <translations> + <file path="generated_resources_no.xtb" lang="nb" /> + <file path="generated_resources_iw.xtb" lang="he" /> + </translations> + <release seq="3"> + <messages></messages> + </release> + </grit>'''), util.PathFromRoot('grit/testdata')) + grd.SetOutputLanguage('en') + grd.RunGatherers() + if __name__ == '__main__': unittest.main() diff --git a/grit/testdata/generated_resources_iw.xtb b/grit/testdata/generated_resources_iw.xtb new file mode 100644 index 0000000..86b5533 --- /dev/null +++ b/grit/testdata/generated_resources_iw.xtb @@ -0,0 +1,4 @@ +<?xml version="1.0" ?> +<!DOCTYPE translationbundle> +<translationbundle lang="iw"> +</translationbundle> diff --git a/grit/testdata/generated_resources_no.xtb b/grit/testdata/generated_resources_no.xtb new file mode 100644 index 0000000..913638b --- /dev/null +++ b/grit/testdata/generated_resources_no.xtb @@ -0,0 +1,4 @@ +<?xml version="1.0" ?> +<!DOCTYPE translationbundle> +<translationbundle lang="no"> +</translationbundle> |