Commit d2f53be1 authored by sergeyu's avatar sergeyu Committed by Commit Bot

Skip missing translations when generating JSON resources.

It doesn't make sense to replace missing translations with english
strings because Chrome can do this automatically when getting
resources.

BUG=369572

Review-Url: https://codereview.chromium.org/1676793002
Cr-Commit-Position: refs/heads/master@{#480994}
parent d98c08f7
#!/usr/bin/env python
# Copyright (c) 2012 The Chromium Authors. All rights reserved. # Copyright (c) 2012 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be # Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. # found in the LICENSE file.
...@@ -31,6 +30,12 @@ def Format(root, lang='en', output_dir='.'): ...@@ -31,6 +30,12 @@ def Format(root, lang='en', output_dir='.'):
if id.startswith('IDR_') or id.startswith('IDS_'): if id.startswith('IDR_') or id.startswith('IDS_'):
id = id[4:] id = id[4:]
translation_missing = child.GetCliques()[0].clique.get(lang) is None;
if child.ShouldFallbackToEnglish() and translation_missing:
# Skip the string if it's not translated. Chrome will fallback
# to English automatically.
continue
loc_message = encoder.encode(child.ws_at_start + child.Translate(lang) + loc_message = encoder.encode(child.ws_at_start + child.Translate(lang) +
child.ws_at_end) child.ws_at_end)
......
...@@ -108,7 +108,8 @@ class ChromeMessagesJsonFormatUnittest(unittest.TestCase): ...@@ -108,7 +108,8 @@ class ChromeMessagesJsonFormatUnittest(unittest.TestCase):
""") """)
buf = StringIO.StringIO() buf = StringIO.StringIO()
build.RcBuilder.ProcessNode(root, DummyOutput('chrome_messages_json', 'fr'), buf) build.RcBuilder.ProcessNode(root, DummyOutput('chrome_messages_json', 'fr'),
buf)
output = buf.getvalue() output = buf.getvalue()
test = u""" test = u"""
{ {
...@@ -118,6 +119,31 @@ class ChromeMessagesJsonFormatUnittest(unittest.TestCase): ...@@ -118,6 +119,31 @@ class ChromeMessagesJsonFormatUnittest(unittest.TestCase):
"ID_HELLO_USER": { "ID_HELLO_USER": {
"message": "H\\u00e9P\\u00e9ll\\u00f4P\\u00f4 %s" "message": "H\\u00e9P\\u00e9ll\\u00f4P\\u00f4 %s"
} }
}
"""
self.assertEqual(test.strip(), output.strip())
def testSkipMissingTranslations(self):
grd = """<?xml version="1.0" encoding="UTF-8"?>
<grit latest_public_release="2" current_release="3" source_lang_id="en"
base_dir="%s">
<outputs>
</outputs>
<release seq="3" allow_pseudo="False">
<messages fallback_to_english="true">
<message name="ID_HELLO_NO_TRANSLATION">Hello not translated</message>
</messages>
</release>
</grit>"""
root = grd_reader.Parse(StringIO.StringIO(grd), dir=".")
buf = StringIO.StringIO()
build.RcBuilder.ProcessNode(root, DummyOutput('chrome_messages_json', 'fr'),
buf)
output = buf.getvalue()
test = u"""
{
} }
""" """
self.assertEqual(test.strip(), output.strip()) self.assertEqual(test.strip(), output.strip())
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment