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

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

Issue 7994004: Initial source commit to grit-i18n project. (Closed) Base URL: http://grit-i18n.googlecode.com/svn/trunk/
Patch Set: Created 9 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 | Annotate | Revision Log
« no previous file with comments | « grit/format/interface.py ('k') | grit/format/js_map_format_unittest.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 #!/usr/bin/python2.4
2 #
3 # Copyright (c) 2009 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file.
6
7 """Formats as a .js file using a map: <english text> -> <localized text>.
8 """
9
10 import os
11 import re
12 import types
13
14 from grit import util
15 from grit.format import interface
16 from grit.node import io
17
18
19 class TopLevel(interface.ItemFormatter):
20 """Writes out the required preamble for JS files."""
21
22 def Format(self, item, lang='en', begin_item=True, output_dir='.'):
23 """Format the JS file header."""
24 assert isinstance(lang, types.StringTypes)
25 if not begin_item:
26 return ''
27 else:
28 return '''// Copyright %d Google Inc. All Rights Reserved.
29 // This file is automatically generated by GRIT. Do not edit.
30 ''' % (util.GetCurrentYear())
31
32
33 class StringTable(interface.ItemFormatter):
34 """Writes out the string table."""
35
36 def Format(self, item, lang='en', begin_item=True, output_dir='.'):
37 if begin_item:
38 return ''
39 else:
40 return '\n'
41
42
43 class Message(interface.ItemFormatter):
44 """Writes out a single message."""
45
46 def Format(self, item, lang='en', begin_item=True, output_dir='.'):
47 """Format a single message."""
48 if not begin_item:
49 return ''
50
51 from grit.node import message
52
53 assert isinstance(lang, types.StringTypes)
54 assert isinstance(item, message.MessageNode)
55
56 en_message = item.ws_at_start + item.Translate('en') + item.ws_at_end
57 # Remove position numbers from placeholders.
58 en_message = re.sub(r'%\d\$([a-z])', r'%\1', en_message)
59 # Escape double quotes.
60 en_message = re.sub(r'"', r'\"', en_message)
61
62 loc_message = item.ws_at_start + item.Translate(lang) + item.ws_at_end
63 # Escape double quotes.
64 loc_message = re.sub(r'"', r'\"', loc_message)
65
66 return '\nlocalizedStrings["%s"] = "%s";' % (en_message, loc_message)
OLDNEW
« no previous file with comments | « grit/format/interface.py ('k') | grit/format/js_map_format_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698