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..8c86dfe6edecc96a27c5a4a9ba63e13670cc72e9 |
--- /dev/null |
+++ b/grit/format/chrome_messages_json.py |
@@ -0,0 +1,40 @@ |
+#!/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) |
Jói
2012/10/15 10:31:06
What about \ in the message, do they need to be es
Sergey Ulanov
2012/10/16 00:50:24
That's a good point. I took these two lines from j
|
+ |
+ 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) |