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

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

Issue 9965022: Allow substitution of messages as variables in other messages. (Closed) Base URL: https://grit-i18n.googlecode.com/svn/trunk
Patch Set: Fix unit tests for policy writers. Created 8 years, 8 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/policy_templates/template_formatter.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 .js file using a map: <english text> -> <localized text>. 6 """Formats as a .js file using a map: <english text> -> <localized text>.
7 """ 7 """
8 8
9 import os 9 import os
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.format import interface 14 from grit.format import interface
15 from grit.node import io 15 from grit.node import io
16 16
17 17
18 class TopLevel(interface.ItemFormatter): 18 class TopLevel(interface.ItemFormatter):
19 """Writes out the required preamble for JS files.""" 19 """Writes out the required preamble for JS files."""
20 20
21 def Format(self, item, lang='en', begin_item=True, output_dir='.'): 21 def Format(self, item, lang='en', output_dir='.'):
22 """Format the JS file header.""" 22 """Format the JS file header."""
23 assert isinstance(lang, types.StringTypes) 23 assert isinstance(lang, types.StringTypes)
24 if not begin_item: 24 return '''// Copyright %d Google Inc. All Rights Reserved.
25 return ''
26 else:
27 return '''// Copyright %d Google Inc. All Rights Reserved.
28 // This file is automatically generated by GRIT. Do not edit. 25 // This file is automatically generated by GRIT. Do not edit.
29 ''' % (util.GetCurrentYear()) 26 ''' % (util.GetCurrentYear())
30 27
31 28
32 class StringTable(interface.ItemFormatter): 29 class StringTable(interface.ItemFormatter):
33 """Writes out the string table.""" 30 """Writes out the string table."""
34 31
35 def Format(self, item, lang='en', begin_item=True, output_dir='.'): 32 def FormatEnd(self, item, lang='en', output_dir='.'):
36 if begin_item: 33 return '\n'
37 return ''
38 else:
39 return '\n'
40 34
41 35
42 class Message(interface.ItemFormatter): 36 class Message(interface.ItemFormatter):
43 """Writes out a single message.""" 37 """Writes out a single message."""
44 38
45 def Format(self, item, lang='en', begin_item=True, output_dir='.'): 39 def Format(self, item, lang='en', output_dir='.'):
46 """Format a single message.""" 40 """Format a single message."""
47 if not begin_item:
48 return ''
49
50 from grit.node import message 41 from grit.node import message
51 42
52 assert isinstance(lang, types.StringTypes) 43 assert isinstance(lang, types.StringTypes)
53 assert isinstance(item, message.MessageNode) 44 assert isinstance(item, message.MessageNode)
54 45
55 en_message = item.ws_at_start + item.Translate('en') + item.ws_at_end 46 en_message = item.ws_at_start + item.Translate('en') + item.ws_at_end
56 # Remove position numbers from placeholders. 47 # Remove position numbers from placeholders.
57 en_message = re.sub(r'%\d\$([a-z])', r'%\1', en_message) 48 en_message = re.sub(r'%\d\$([a-z])', r'%\1', en_message)
58 # Escape double quotes. 49 # Escape double quotes.
59 en_message = re.sub(r'"', r'\"', en_message) 50 en_message = re.sub(r'"', r'\"', en_message)
60 51
61 loc_message = item.ws_at_start + item.Translate(lang) + item.ws_at_end 52 loc_message = item.ws_at_start + item.Translate(lang) + item.ws_at_end
62 # Escape double quotes. 53 # Escape double quotes.
63 loc_message = re.sub(r'"', r'\"', loc_message) 54 loc_message = re.sub(r'"', r'\"', loc_message)
64 55
65 return '\nlocalizedStrings["%s"] = "%s";' % (en_message, loc_message) 56 return '\nlocalizedStrings["%s"] = "%s";' % (en_message, loc_message)
OLDNEW
« no previous file with comments | « grit/format/interface.py ('k') | grit/format/policy_templates/template_formatter.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698