aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortony@chromium.org <tony@chromium.org@7262f16d-afe8-6277-6482-052fa10e57b1>2014-04-11 22:03:58 +0000
committertony@chromium.org <tony@chromium.org@7262f16d-afe8-6277-6482-052fa10e57b1>2014-04-11 22:03:58 +0000
commitd769b0cb7974d27fc2e1feda9a2523e0da4a10b9 (patch)
tree781300448207c0674dc1fe6633c58b394072ed3a
parent3cc30808743b43aba1bc37a2c0e4b6fb55746508 (diff)
downloadgrit-d769b0cb7974d27fc2e1feda9a2523e0da4a10b9.tar.gz
Make grit aware that nb and no language codes are equivalent.
Translation console uses non-standard language codes 'iw' and 'no' for Hebrew and Norwegian Bokm\u00e5l instead of 'he' and 'nb' used in Chrome. Previously grit handled that properly for Hebrew, but not for Nerwegian Bokm\u00e5l. Patch by Sergey Ulanov at https://codereview.chromium.org/235893002/ git-svn-id: http://grit-i18n.googlecode.com/svn/trunk@161 7262f16d-afe8-6277-6482-052fa10e57b1
-rw-r--r--grit/node/io.py13
-rw-r--r--grit/node/io_unittest.py16
-rw-r--r--grit/testdata/generated_resources_iw.xtb4
-rw-r--r--grit/testdata/generated_resources_no.xtb4
4 files changed, 32 insertions, 5 deletions
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>