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

Unified Diff: tools/grit/grit/xtb_reader.py

Issue 159148: Add <if> blocks to xtb files in the simplest possible way. This currently (Closed)
Patch Set: comments Created 11 years, 5 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 | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/grit/grit/xtb_reader.py
diff --git a/tools/grit/grit/xtb_reader.py b/tools/grit/grit/xtb_reader.py
index f785879bd099c70d741343e42b24c2f790116c3c..ad29d03f8bf76a5303d693995df8718333a81414 100644
--- a/tools/grit/grit/xtb_reader.py
+++ b/tools/grit/grit/xtb_reader.py
@@ -7,6 +7,7 @@
'''
+import sys
import xml.sax
import xml.sax.handler
@@ -28,6 +29,8 @@ class XtbContentHandler(xml.sax.handler.ContentHandler):
self.current_structure = []
# Set to the language ID when we see the <translationbundle> node.
self.language = ''
+ # Keep track of the if block we're inside. We can't nest ifs.
+ self.if_expr = None
def startElement(self, name, attrs):
if name == 'translation':
@@ -39,13 +42,27 @@ class XtbContentHandler(xml.sax.handler.ContentHandler):
self.current_structure.append((True, attrs.getValue('name')))
elif name == 'translationbundle':
self.language = attrs.getValue('lang')
+ elif name == 'if':
+ assert self.if_expr is None, "Can't nest <if> in xtb files"
+ self.if_expr = attrs.getValue('expr')
def endElement(self, name):
if name == 'translation':
assert self.current_id != 0
- self.callback(self.current_id, self.current_structure)
+
+ # If we're in an if block, only call the callback (add the translation)
+ # if the expression is True.
+ should_run_callback = True
+ if self.if_expr:
+ should_run_callback = eval(self.if_expr, {}, {'os': sys.platform})
+ if should_run_callback:
+ self.callback(self.current_id, self.current_structure)
+
self.current_id = 0
self.current_structure = []
+ elif name == 'if':
+ assert self.if_expr is not None
+ self.if_expr = None
def characters(self, content):
if self.current_id != 0:
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698