diff options
author | tc@google.com <tc@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-22 00:42:23 +0000 |
---|---|---|
committer | tc@google.com <tc@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-22 00:42:23 +0000 |
commit | 4dc3cca352f08bfe126bb83c5a7030965538b7a0 (patch) | |
tree | 2cc164f86f9229b9b215d58e4b53940d34ae99c3 /tools | |
parent | 4730db95815ec2cd4d12063a14cff7cbbeb5fe61 (diff) | |
download | chromium_src-4dc3cca352f08bfe126bb83c5a7030965538b7a0.zip chromium_src-4dc3cca352f08bfe126bb83c5a7030965538b7a0.tar.gz chromium_src-4dc3cca352f08bfe126bb83c5a7030965538b7a0.tar.bz2 |
Add <if> blocks to xtb files in the simplest possible way. This currently
only supports checking the OS, but we can add more information if
necessary.
BUG=16884
Review URL: http://codereview.chromium.org/159148
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@21249 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools')
-rw-r--r-- | tools/grit/grit/xtb_reader.py | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/tools/grit/grit/xtb_reader.py b/tools/grit/grit/xtb_reader.py index f785879..ad29d03 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: |