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

Unified Diff: grit/format/chrome_messages_json.py

Issue 11152002: Add support for messages.json format used to localize Chrome extensions. (Closed) Base URL: http://git.chromium.org/external/grit-i18n.git@master
Patch Set: Created 8 years, 2 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 | « no previous file | grit/format/chrome_messages_json_unittest.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: grit/format/chrome_messages_json.py
diff --git a/grit/format/chrome_messages_json.py b/grit/format/chrome_messages_json.py
new file mode 100644
index 0000000000000000000000000000000000000000..6677c6eac378615bbe71089ac4b1394b69c6716f
--- /dev/null
+++ b/grit/format/chrome_messages_json.py
@@ -0,0 +1,41 @@
+#!/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."""
+
+import re
+import types
+
+from grit import util
+from grit.format import interface
+from grit.node import message
+
+class StringTable(interface.ItemFormatter):
+ """Writes out the string table."""
+
+ def Format(self, item, lang='en', output_dir='.'):
+ out = []
+ out.append('{\n')
+
+ format = (' "%s": {\n'
+ ' "message": "%s"\n'
+ ' }')
+ for child in item.children:
+ if isinstance(child, message.MessageNode):
+ loc_message = child.Translate(lang)
+ loc_message = re.sub(r'\\', r'\\\\', loc_message)
+ loc_message = re.sub(r'"', r'\"', loc_message)
+
+ id = child.attrs['name']
+ if id.startswith('IDR_'):
+ id = id[4:]
+
+ if len(out) > 1:
+ out.append(',\n')
+ out.append(format % (id, loc_message))
+
+ out.append('\n}\n')
+ return ''.join(out)
« no previous file with comments | « no previous file | grit/format/chrome_messages_json_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698