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

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/node/empty.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)
Jói 2012/10/15 10:31:06 What about \ in the message, do they need to be es
Sergey Ulanov 2012/10/16 00:50:24 That's a good point. I took these two lines from j
30
31 id = child.attrs['name']
32 if id.startswith('IDR_'):
33 id = id[4:]
34
35 if len(out) > 1:
36 out.append(',\n')
37 out.append(format % (id, loc_message))
38
39 out.append('\n}\n')
40 return ''.join(out)
OLDNEW
« no previous file with comments | « no previous file | grit/node/empty.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698