Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(312)

Unified Diff: grit/format/android_xml.py

Issue 1291173002: Remove support for product attributes in Android xml files. (Closed) Base URL: http://grit-i18n.googlecode.com/svn/trunk
Patch Set: fixed >80 line Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | grit/format/android_xml_unittest.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: grit/format/android_xml.py
diff --git a/grit/format/android_xml.py b/grit/format/android_xml.py
index a04f35e18818bb28fbbcf31dfcc163f5ca2081fa..be9d79546d973fb0d6a0e7c15655f15f9ab9f254 100644
--- a/grit/format/android_xml.py
+++ b/grit/format/android_xml.py
@@ -42,19 +42,22 @@ ANDROID_JAVA_TAGGED_ONLY to "true" when building the grd file. For example:
<message name="IDS_HELLO" formatter_data="android_java">Hello</message>
-To specify the product attribute to be added to a <string> element, add
-"android_java_product" to formatter_data. "android_java_name" can be used to
-override the name in the <string> element. For example,
-
- <message name="IDS_FOO_NOSDCARD" formatter_data="android_java_product=nosdcard
- android_java_name=foo">no card</message>
- <message name="IDS_FOO_DEFAULT" formatter_data="android_java_product=default
- android_java_name=foo">has card</message>
-
-would generate
-
- <string name="foo" product="nosdcard">"no card"</string>
- <string name="foo" product="default">"has card"</string>
+To generate Android plurals (aka "quantity strings"), use the ICU plural syntax
+in the grd file. This will automatically be transformed into a <purals> element
+in the output xml file. For example:
+
+ <message name="IDS_CATS">
+ {NUM_CATS, plural,
+ =1 {1 cat}
+ other {# cats}}
+ </message>
+
+ will produce
+
+ <plurals name="cats">
+ <item quantity="one">1 Katze</item>
+ <item quantity="other">%d Katzen</item>
+ </plurals>
"""
import os
@@ -74,30 +77,13 @@ _TAGGED_ONLY_DEFAULT = False
# In tagged-only mode, only messages with this tag will be ouputted.
_EMIT_TAG = 'android_java'
-# This tag controls the product attribute of the generated <string> element.
-_PRODUCT_TAG = 'android_java_product'
-
-# This tag controls the name attribute of the generated <string> element.
-_NAME_TAG = 'android_java_name'
-
-# The Android resource name and optional product information are placed
-# in the grd string name because grd doesn't know about Android product
-# information.
-# TODO(newt): Don't allow product information in mangled names, since it can now
-# be specified using "android_java_product" in formatter_data.
-_NAME_PATTERN = lazy_re.compile(
- 'IDS_(?P<name>[A-Z0-9_]+)(_product_(?P<product>[a-z]+))?\Z')
+_NAME_PATTERN = lazy_re.compile('IDS_(?P<name>[A-Z0-9_]+)\Z')
+# Most strings are output as a <string> element. Note the double quotes
+# around the value to preserve whitespace.
+_STRING_TEMPLATE = u'<string name="%s">"%s"</string>\n'
-# In most cases we only need a name attribute and string value.
-_SIMPLE_TEMPLATE = u'<string name="%s">%s</string>\n'
-
-
-# In a few cases a product attribute is needed.
-_PRODUCT_TEMPLATE = u'<string name="%s" product="%s">%s</string>\n'
-
-
-# Some strings have a plural equivalent
+# Some strings are output as a <plurals> element.
_PLURALS_TEMPLATE = '<plurals name="%s">\n%s</plurals>\n'
_PLURALS_ITEM_TEMPLATE = ' <item quantity="%s">%s</item>\n'
_PLURALS_PATTERN = lazy_re.compile(r'\{[A-Z_]+,\s*plural,(?P<items>.*)\}$', flags=re.S)
@@ -196,28 +182,19 @@ def _FormatPluralMessage(message):
def _FormatMessage(item, lang):
"""Writes out a single string as a <resource/> element."""
- value = item.ws_at_start + item.Translate(lang) + item.ws_at_end
- # Replace < > & with &lt; &gt; &amp; to ensure we generate valid XML and
- # replace ' " with \' \" to conform to Android's string formatting rules.
- value = xml.sax.saxutils.escape(value, {"'": "\\'", '"': '\\"'})
- plurals = _FormatPluralMessage(value)
- # Wrap the string in double quotes to preserve whitespace.
- value = '"' + value + '"'
-
mangled_name = item.GetTextualIds()[0]
match = _NAME_PATTERN.match(mangled_name)
if not match:
raise Exception('Unexpected resource name: %s' % mangled_name)
name = match.group('name').lower()
- product = match.group('product')
- # Override product or name with values in formatter_data, if any.
- product = item.formatter_data.get(_PRODUCT_TAG, product)
- name = item.formatter_data.get(_NAME_TAG, name)
+ value = item.ws_at_start + item.Translate(lang) + item.ws_at_end
+ # Replace < > & with &lt; &gt; &amp; to ensure we generate valid XML and
+ # replace ' " with \' \" to conform to Android's string formatting rules.
+ value = xml.sax.saxutils.escape(value, {"'": "\\'", '"': '\\"'})
+ plurals = _FormatPluralMessage(value)
if plurals:
return _PLURALS_TEMPLATE % (name, plurals)
- elif product:
- return _PRODUCT_TEMPLATE % (name, product, value)
else:
- return _SIMPLE_TEMPLATE % (name, value)
+ return _STRING_TEMPLATE % (name, value)
« no previous file with comments | « no previous file | grit/format/android_xml_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698