OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """Produces localized strings.xml files for Android. | 6 """Produces localized strings.xml files for Android. |
7 | 7 |
8 In cases where an "android" type output file is requested in a grd, the classes | 8 In cases where an "android" type output file is requested in a grd, the classes |
9 in android_xml will process the messages and translations to produce a valid | 9 in android_xml will process the messages and translations to produce a valid |
10 strings.xml that is properly localized with the specified language. | 10 strings.xml that is properly localized with the specified language. |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 if _TAGGED_ONLY_ENV_VAR in os.environ: | 105 if _TAGGED_ONLY_ENV_VAR in os.environ: |
106 tagged_only = os.environ[_TAGGED_ONLY_ENV_VAR].lower() | 106 tagged_only = os.environ[_TAGGED_ONLY_ENV_VAR].lower() |
107 if tagged_only == 'true': | 107 if tagged_only == 'true': |
108 tagged_only = True | 108 tagged_only = True |
109 elif tagged_only == 'false': | 109 elif tagged_only == 'false': |
110 tagged_only = False | 110 tagged_only = False |
111 else: | 111 else: |
112 raise Exception('env variable ANDROID_JAVA_TAGGED_ONLY must have value ' | 112 raise Exception('env variable ANDROID_JAVA_TAGGED_ONLY must have value ' |
113 'true or false. Invalid value: %s' % tagged_only) | 113 'true or false. Invalid value: %s' % tagged_only) |
114 | 114 |
115 for item in root.Preorder(): | 115 for item in root.ActiveDescendants(): |
116 with item: | 116 with item: |
117 if ShouldOutputNode(item, tagged_only): | 117 if ShouldOutputNode(item, tagged_only): |
118 yield _FormatMessage(item, lang) | 118 yield _FormatMessage(item, lang) |
119 | 119 |
120 yield '</resources>\n' | 120 yield '</resources>\n' |
121 | 121 |
122 | 122 |
123 def ShouldOutputNode(node, tagged_only): | 123 def ShouldOutputNode(node, tagged_only): |
124 """Returns true if node should be outputted. | 124 """Returns true if node should be outputted. |
125 | 125 |
(...skipping 23 matching lines...) Expand all Loading... |
149 product = match.group('product') | 149 product = match.group('product') |
150 | 150 |
151 # Override product or name with values in formatter_data, if any. | 151 # Override product or name with values in formatter_data, if any. |
152 product = item.formatter_data.get(_PRODUCT_TAG, product) | 152 product = item.formatter_data.get(_PRODUCT_TAG, product) |
153 name = item.formatter_data.get(_NAME_TAG, name) | 153 name = item.formatter_data.get(_NAME_TAG, name) |
154 | 154 |
155 if product: | 155 if product: |
156 return _PRODUCT_TEMPLATE % (name, product, value) | 156 return _PRODUCT_TEMPLATE % (name, product, value) |
157 else: | 157 else: |
158 return _SIMPLE_TEMPLATE % (name, value) | 158 return _SIMPLE_TEMPLATE % (name, value) |
OLD | NEW |