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

Unified Diff: tools/grit/grit/tool/menu_from_parts.py

Issue 1410853008: Move grit from DEPS into src. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: webview licenses Created 5 years, 1 month 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/interface.py ('k') | tools/grit/grit/tool/newgrd.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/grit/grit/tool/menu_from_parts.py
diff --git a/tools/grit/grit/tool/menu_from_parts.py b/tools/grit/grit/tool/menu_from_parts.py
new file mode 100755
index 0000000000000000000000000000000000000000..36d2d4086acf2c4d0f3bf4bbcbae1d3cf3c1fd9f
--- /dev/null
+++ b/tools/grit/grit/tool/menu_from_parts.py
@@ -0,0 +1,79 @@
+#!/usr/bin/env python
+# Copyright (c) 2012 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+'''The 'grit menufromparts' tool.'''
+
+import types
+
+from grit import grd_reader
+from grit import tclib
+from grit import util
+from grit import xtb_reader
+from grit.tool import interface
+from grit.tool import transl2tc
+
+import grit.extern.tclib
+
+
+class MenuTranslationsFromParts(interface.Tool):
+ '''One-off tool to generate translated menu messages (where each menu is kept
+in a single message) based on existing translations of the individual menu
+items. Was needed when changing menus from being one message per menu item
+to being one message for the whole menu.'''
+
+ def ShortDescription(self):
+ return ('Create translations of whole menus from existing translations of '
+ 'menu items.')
+
+ def Run(self, globopt, args):
+ self.SetOptions(globopt)
+ assert len(args) == 2, "Need exactly two arguments, the XTB file and the output file"
+
+ xtb_file = args[0]
+ output_file = args[1]
+
+ grd = grd_reader.Parse(self.o.input, debug=self.o.extra_verbose)
+ grd.OnlyTheseTranslations([]) # don't load translations
+ grd.RunGatherers()
+
+ xtb = {}
+ def Callback(msg_id, parts):
+ msg = []
+ for part in parts:
+ if part[0]:
+ msg = []
+ break # it had a placeholder so ignore it
+ else:
+ msg.append(part[1])
+ if len(msg):
+ xtb[msg_id] = ''.join(msg)
+ with open(xtb_file) as f:
+ xtb_reader.Parse(f, Callback)
+
+ translations = [] # list of translations as per transl2tc.WriteTranslations
+ for node in grd:
+ if node.name == 'structure' and node.attrs['type'] == 'menu':
+ assert len(node.GetCliques()) == 1
+ message = node.GetCliques()[0].GetMessage()
+ translation = []
+
+ contents = message.GetContent()
+ for part in contents:
+ if isinstance(part, types.StringTypes):
+ id = grit.extern.tclib.GenerateMessageId(part)
+ if id not in xtb:
+ print "WARNING didn't find all translations for menu %s" % node.attrs['name']
+ translation = []
+ break
+ translation.append(xtb[id])
+ else:
+ translation.append(part.GetPresentation())
+
+ if len(translation):
+ translations.append([message.GetId(), ''.join(translation)])
+
+ with util.WrapOutputStream(open(output_file, 'w')) as f:
+ transl2tc.TranslationToTc.WriteTranslations(f, translations)
+
« no previous file with comments | « tools/grit/grit/tool/interface.py ('k') | tools/grit/grit/tool/newgrd.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698