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

Unified Diff: grit/format/chrome_messages_json.py

Issue 18860003: Use JSONEncoder to escape JSON strings. (Closed) Base URL: https://grit-i18n.googlecode.com/svn/trunk
Patch Set: Created 7 years, 5 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
index 560912288b1562e483c07cfbf1bd35e2af1f30c5..7b370d7fdca26ed966b45ad0a42c709715b8885b 100644
--- a/grit/format/chrome_messages_json.py
+++ b/grit/format/chrome_messages_json.py
@@ -6,6 +6,7 @@
"""Formats as a .json file that can be used to localize Google Chrome
extensions."""
+from json import JSONEncoder
import re
import types
@@ -16,20 +17,19 @@ def Format(root, lang='en', output_dir='.'):
"""Format the messages as JSON."""
yield '{\n'
+ encoder = JSONEncoder();
format = (' "%s": {\n'
- ' "message": "%s"\n'
+ ' "message": %s\n'
' }')
first = True
for child in root.ActiveDescendants():
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:]
+ loc_message = encoder.encode(child.Translate(lang))
+
if not first:
yield ',\n'
first = False
« 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