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

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

Issue 11152002: Add support for messages.json format used to localize Chrome extensions. (Closed) Base URL: http://git.chromium.org/external/grit-i18n.git@master
Patch Set: Created 8 years, 2 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
« 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
(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 import re
10 import types
11
12 from grit import util
13 from grit.format import interface
14 from grit.node import message
15
16 class StringTable(interface.ItemFormatter):
17 """Writes out the string table."""
18
19 def Format(self, item, lang='en', output_dir='.'):
20 out = []
21 out.append('{\n')
22
23 format = (' "%s": {\n'
24 ' "message": "%s"\n'
25 ' }')
26 for child in item.children:
27 if isinstance(child, message.MessageNode):
28 loc_message = child.Translate(lang)
29 loc_message = re.sub(r'\\', r'\\\\', loc_message)
30 loc_message = re.sub(r'"', r'\"', loc_message)
31
32 id = child.attrs['name']
33 if id.startswith('IDR_'):
34 id = id[4:]
35
36 if len(out) > 1:
37 out.append(',\n')
38 out.append(format % (id, loc_message))
39
40 out.append('\n}\n')
41 return ''.join(out)
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