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

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

Issue 1438403002: Remove contents of grit's git-svn-mirror repository. (Closed) Base URL: https://chromium.googlesource.com/external/grit-i18n@master
Patch Set: 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 unified diff | Download patch
« no previous file with comments | « grit/format/c_format_unittest.py ('k') | 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
(Empty)
1 #!/usr/bin/env python
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
4 # found in the LICENSE file.
5
6 """Formats as a .json file that can be used to localize Google Chrome
7 extensions."""
8
9 from json import JSONEncoder
10 import re
11 import types
12
13 from grit import util
14 from grit.node import message
15
16 def Format(root, lang='en', output_dir='.'):
17 """Format the messages as JSON."""
18 yield '{\n'
19
20 encoder = JSONEncoder();
21 format = (' "%s": {\n'
22 ' "message": %s\n'
23 ' }')
24 first = True
25 for child in root.ActiveDescendants():
26 if isinstance(child, message.MessageNode):
27 id = child.attrs['name']
28 if id.startswith('IDR_') or id.startswith('IDS_'):
29 id = id[4:]
30
31 loc_message = encoder.encode(child.ws_at_start + child.Translate(lang) +
32 child.ws_at_end)
33
34 if not first:
35 yield ',\n'
36 first = False
37 yield format % (id, loc_message)
38
39 yield '\n}\n'
OLDNEW
« no previous file with comments | « grit/format/c_format_unittest.py ('k') | grit/format/chrome_messages_json_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698