Reviewers: kelvinp
CL:
https://codereview.chromium.org/1425693007/
Message:
ptal
Description:
Fix placeholder syntax for Chrome extensions.
This changes the output format for placeholders in Chrome extensions from $n
(which is ambiguous in some circumstances) to $var$. For simplicity (and to
keep
the file size small), |var| is always |n|; in other words, we use
placeholders
named $1$, $2$, etc., regardless of the name given in the GRD file.
BUG=551100
Base URL:
https://chromium.googlesource.com/external/grit-i18n.git@master
Affected files (+19, -2 lines):
M grit/format/chrome_messages_json.py
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'
+ ' "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):
+ 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'