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..7cd0e28b98d9bb6dfa24355c7a901c42531deb4e 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\n%s' |
' }') |
+ placeholder_format = (' "%i": {\n' |
kelvinp
2015/11/04 19:02:10
According to the documentation, the placeholder is
kelvinp
2015/11/04 19:09:04
Spoke with Jamie offline. We want to minimize tex
Jamie
2015/11/04 19:13:55
It's only optional insofar as you don't need it fo
|
+ ' "content": "$%i"\n' |
+ ' }') |
first = True |
for child in root.ActiveDescendants(): |
if isinstance(child, message.MessageNode): |
@@ -31,9 +34,23 @@ 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. |
+ placeholders = '' |
+ for i in range(1, 10): |
kelvinp
2015/11/04 19:02:10
Is 10 the maximum number of placeholders?
Nevermin
kelvinp
2015/11/04 19:09:04
May be good to include the link about there can on
Jamie
2015/11/04 19:13:55
Acknowledged.
|
+ 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' |