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

Unified Diff: grit/gather/tr_html.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/gather/skeleton_gatherer.py ('k') | grit/node/base.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: grit/gather/tr_html.py
diff --git a/grit/gather/tr_html.py b/grit/gather/tr_html.py
index d4cd98a724f9c29cefa456e72cf17fb4133b52b5..05e473178f92116e9657ca4c84f4425b5b7e71d3 100644
--- a/grit/gather/tr_html.py
+++ b/grit/gather/tr_html.py
@@ -693,7 +693,7 @@ class TrHtml(interface.GathererBase):
self.skeleton_[ix] = msg.GetRealContent()
- # Static method
+ @staticmethod
def FromFile(html, extkey=None, encoding = 'utf-8'):
'''Creates a TrHtml object from the contents of 'html' which are decoded
using 'encoding'. Returns a new TrHtml object, upon which Parse() has not
@@ -717,5 +717,23 @@ class TrHtml(interface.GathererBase):
doc = doc[1:]
return TrHtml(doc)
- FromFile = staticmethod(FromFile)
+
+ def SubstituteMessages(self, substituter):
+ '''Applies substitutions to all messages in the tree.
+
+ Goes through the skeleton and finds all MessageCliques.
+
+ Args:
+ substituter: a grit.util.Substituter object.
+ '''
+ new_skel = []
+ for chunk in self.skeleton_:
+ if isinstance(chunk, clique.MessageClique):
+ old_message = chunk.GetMessage()
+ new_message = substituter.SubstituteMessage(old_message)
+ if new_message is not old_message:
+ new_skel.append(self.uberclique.MakeClique(new_message))
+ continue
+ new_skel.append(chunk)
+ self.skeleton_ = new_skel
« no previous file with comments | « grit/gather/skeleton_gatherer.py ('k') | grit/node/base.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698