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

Side by Side Diff: grit/format/chrome_messages_json.py

Issue 138903021: Strip IDS_ as well as IDR_ in the chrome_messages_json generator. (Closed) Base URL: http://grit-i18n.googlecode.com/svn/trunk/
Patch Set: Created 6 years, 11 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | grit/format/chrome_messages_json_unittest.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """Formats as a .json file that can be used to localize Google Chrome 6 """Formats as a .json file that can be used to localize Google Chrome
7 extensions.""" 7 extensions."""
8 8
9 from json import JSONEncoder 9 from json import JSONEncoder
10 import re 10 import re
11 import types 11 import types
12 12
13 from grit import util 13 from grit import util
14 from grit.node import message 14 from grit.node import message
15 15
16 def Format(root, lang='en', output_dir='.'): 16 def Format(root, lang='en', output_dir='.'):
17 """Format the messages as JSON.""" 17 """Format the messages as JSON."""
18 yield '{\n' 18 yield '{\n'
19 19
20 encoder = JSONEncoder(); 20 encoder = JSONEncoder();
21 format = (' "%s": {\n' 21 format = (' "%s": {\n'
22 ' "message": %s\n' 22 ' "message": %s\n'
23 ' }') 23 ' }')
24 first = True 24 first = True
25 for child in root.ActiveDescendants(): 25 for child in root.ActiveDescendants():
26 if isinstance(child, message.MessageNode): 26 if isinstance(child, message.MessageNode):
27 id = child.attrs['name'] 27 id = child.attrs['name']
28 if id.startswith('IDR_'): 28 if id.startswith('IDR_') or id.startswith('IDS_'):
29 id = id[4:] 29 id = id[4:]
30 30
31 loc_message = encoder.encode(child.Translate(lang)) 31 loc_message = encoder.encode(child.Translate(lang))
32 32
33 if not first: 33 if not first:
34 yield ',\n' 34 yield ',\n'
35 first = False 35 first = False
36 yield format % (id, loc_message) 36 yield format % (id, loc_message)
37 37
38 yield '\n}\n' 38 yield '\n}\n'
OLDNEW
« 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