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

Unified Diff: grit/format/c_format.py

Issue 9965022: Allow substitution of messages as variables in other messages. (Closed) Base URL: https://grit-i18n.googlecode.com/svn/trunk
Patch Set: Fix unit tests for policy writers. Created 8 years, 9 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 | « grit/clique_unittest.py ('k') | grit/format/data_pack.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: grit/format/c_format.py
diff --git a/grit/format/c_format.py b/grit/format/c_format.py
index c9497f046832b1aefdbe1c5f61cc87c9cd3c1fb7..f346c127e8b6cdcc7271dd7f166c96003163eff9 100644
--- a/grit/format/c_format.py
+++ b/grit/format/c_format.py
@@ -18,20 +18,18 @@ from grit.node import io
class TopLevel(interface.ItemFormatter):
"""Writes out the required preamble for C files."""
- def Format(self, item, lang='en', begin_item=True, output_dir='.'):
+ def Format(self, item, lang='en', output_dir='.'):
+ """Format the C file header."""
assert isinstance(lang, types.StringTypes)
- if not begin_item:
- return ''
- else:
- # Find the location of the resource header file, so that we can include
- # it.
- resource_header = 'resource.h' # fall back to this
- for output in item.GetRoot().GetOutputFiles():
- if output.attrs['type'] == 'rc_header':
- resource_header = os.path.abspath(output.GetOutputFilename())
- resource_header = util.MakeRelativePath(output_dir,
- resource_header)
- return """// Copyright %d Google Inc. All Rights Reserved.
+ # Find the location of the resource header file, so that we can include
+ # it.
+ resource_header = 'resource.h' # fall back to this
+ for output in item.GetRoot().GetOutputFiles():
+ if output.attrs['type'] == 'rc_header':
+ resource_header = os.path.abspath(output.GetOutputFilename())
+ resource_header = util.MakeRelativePath(output_dir,
+ resource_header)
+ return """// Copyright %d Google Inc. All Rights Reserved.
// This file is automatically generated by GRIT. Do not edit.
#include "%s"
@@ -44,12 +42,16 @@ class TopLevel(interface.ItemFormatter):
class StringTable(interface.ItemFormatter):
"""Outputs a C switch statement representing the string table."""
- def Format(self, item, lang='en', begin_item=True, output_dir='.'):
+ def Format(self, item, lang='en', output_dir='.'):
+ """Format the start of the table."""
assert isinstance(lang, types.StringTypes)
- if begin_item:
- return 'const char* GetString(int id) {\n switch (id) {'
- else:
- return '\n default:\n return 0;\n }\n}'
+ return 'const char* GetString(int id) {\n switch (id) {'
+
+ def FormatEnd(self, item, lang='en', output_dir='.'):
+ """Format the end of the table."""
+ assert isinstance(lang, types.StringTypes)
+ return '\n default:\n return 0;\n }\n}'
+
def _HexToOct(match):
"Return the octal form of the hex numbers"
@@ -61,14 +63,13 @@ def _HexToOct(match):
hex = hex[4:]
return match.group("escaped_backslashes") + result
+
class Message(interface.ItemFormatter):
"""Writes out a single message as part of the switch."""
- def Format(self, item, lang='en', begin_item=True, output_dir='.'):
+ def Format(self, item, lang='en', output_dir='.'):
+ """Format a single message."""
from grit.node import message
- if not begin_item:
- return ''
-
assert isinstance(lang, types.StringTypes)
assert isinstance(item, message.MessageNode)
« no previous file with comments | « grit/clique_unittest.py ('k') | grit/format/data_pack.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698