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

Unified Diff: tools/grit/grit/format/chrome_messages_json.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
Index: tools/grit/grit/format/chrome_messages_json.py
diff --git a/tools/grit/grit/format/chrome_messages_json.py b/tools/grit/grit/format/chrome_messages_json.py
new file mode 100755
index 0000000000000000000000000000000000000000..be934ab1175924657a79796dbf0def4c2464ec5f
--- /dev/null
+++ b/tools/grit/grit/format/chrome_messages_json.py
@@ -0,0 +1,39 @@
+#!/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.
+
+"""Formats as a .json file that can be used to localize Google Chrome
+extensions."""
+
+from json import JSONEncoder
+import re
+import types
+
+from grit import util
+from grit.node import message
+
+def Format(root, lang='en', output_dir='.'):
+ """Format the messages as JSON."""
+ yield '{\n'
+
+ encoder = JSONEncoder();
+ format = (' "%s": {\n'
+ ' "message": %s\n'
+ ' }')
+ first = True
+ for child in root.ActiveDescendants():
+ if isinstance(child, message.MessageNode):
+ id = child.attrs['name']
+ if id.startswith('IDR_') or id.startswith('IDS_'):
+ id = id[4:]
+
+ loc_message = encoder.encode(child.ws_at_start + child.Translate(lang) +
+ child.ws_at_end)
+
+ if not first:
+ yield ',\n'
+ first = False
+ yield format % (id, loc_message)
+
+ yield '\n}\n'
« no previous file with comments | « tools/grit/grit/format/c_format_unittest.py ('k') | tools/grit/grit/format/chrome_messages_json_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698