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

Unified Diff: grit/format/chrome_messages_json.py

Issue 1425693007: Fix placeholder syntax for Chrome extensions. (Closed) Base URL: https://chromium.googlesource.com/external/grit-i18n.git@master
Patch Set: Added unit test. 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 | « 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 be934ab1175924657a79796dbf0def4c2464ec5f..27ac36135f40b727c36fd669bc34902ef407781b 100644
--- a/grit/format/chrome_messages_json.py
+++ b/grit/format/chrome_messages_json.py
@@ -19,8 +19,11 @@ def Format(root, lang='en', output_dir='.'):
encoder = JSONEncoder();
format = (' "%s": {\n'
- ' "message": %s\n'
+ ' "message": %s%s\n'
' }')
+ placeholder_format = (' "%i": {\n'
+ ' "content": "$%i"\n'
+ ' }')
first = True
for child in root.ActiveDescendants():
if isinstance(child, message.MessageNode):
@@ -31,9 +34,24 @@ def Format(root, lang='en', output_dir='.'):
loc_message = encoder.encode(child.ws_at_start + child.Translate(lang) +
child.ws_at_end)
+ # Replace $n place-holders with $n$ and add an appropriate "placeholders"
+ # entry. Note that chrome.i18n.getMessage only supports 9 placeholders:
+ # https://developer.chrome.com/extensions/i18n#method-getMessage
+ placeholders = ''
+ for i in range(1, 10):
+ if loc_message.find('$%d' % i) == -1:
+ break
+ loc_message = loc_message.replace('$%d' % i, '$%d$' % i)
+ if placeholders:
+ placeholders += ',\n'
+ placeholders += placeholder_format % (i, i)
+
if not first:
yield ',\n'
first = False
- yield format % (id, loc_message)
+
+ if placeholders:
+ placeholders = ',\n "placeholders": {\n%s\n }' % placeholders
+ yield format % (id, loc_message, placeholders)
yield '\n}\n'
« 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