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

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

Issue 2655003: Make ChromeOS's options dialog wider for it and da. (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: remove un-informative comment per tony Created 10 years, 6 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 | « tools/grit/grit/tool/build.py ('k') | 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 ad29d03f8bf76a5303d693995df8718333a81414..826361497ecd557764cad158eefcfc1318687302 100644
--- a/tools/grit/grit/xtb_reader.py
+++ b/tools/grit/grit/xtb_reader.py
@@ -17,7 +17,7 @@ class XtbContentHandler(xml.sax.handler.ContentHandler):
translation in the XTB file.
'''
- def __init__(self, callback, debug=False):
+ def __init__(self, callback, defs=None, debug=False):
self.callback = callback
self.debug = debug
# 0 if we are not currently parsing a translation, otherwise the message
@@ -31,6 +31,11 @@ class XtbContentHandler(xml.sax.handler.ContentHandler):
self.language = ''
# Keep track of the if block we're inside. We can't nest ifs.
self.if_expr = None
+ # Root defines to be used with if expr.
+ if defs:
+ self.defines = defs
+ else:
+ self.defines = {}
def startElement(self, name, attrs):
if name == 'translation':
@@ -50,11 +55,21 @@ class XtbContentHandler(xml.sax.handler.ContentHandler):
if name == 'translation':
assert self.current_id != 0
+ defs = self.defines
+ def pp_ifdef(define):
+ return define in defs
+ def pp_if(define):
+ return define in defs and defs[define]
+
# 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})
+ should_run_callback = eval(self.if_expr, {},
+ {'os': sys.platform,
+ 'defs' : defs,
+ 'pp_ifdef' : pp_ifdef,
+ 'pp_if' : pp_if})
if should_run_callback:
self.callback(self.current_id, self.current_structure)
@@ -86,7 +101,7 @@ class XtbErrorHandler(xml.sax.handler.ErrorHandler):
pass
-def Parse(xtb_file, callback_function, debug=False):
+def Parse(xtb_file, callback_function, defs={}, debug=False):
'''Parse xtb_file, making a call to callback_function for every translation
in the XTB file.
@@ -109,7 +124,8 @@ def Parse(xtb_file, callback_function, debug=False):
front_of_file = xtb_file.read(1024)
xtb_file.seek(front_of_file.find('<translationbundle'))
- handler = XtbContentHandler(callback=callback_function, debug=debug)
+ handler = XtbContentHandler(callback=callback_function, defs=defs,
+ debug=debug)
xml.sax.parse(xtb_file, handler)
assert handler.language != ''
return handler.language
« no previous file with comments | « tools/grit/grit/tool/build.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698