Merge from Chromium at DEPS revision 265802

This commit was generated by merge_to_master.py.

Change-Id: I9b4b5361ccb5171770607734cfb4e0e28bef35d7
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 @@
       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 @@
       <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 @@
     "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 @@
   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 @@
 
   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 @@
                                     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 @@
     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 @@
     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>