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

Side by Side Diff: grit/format/policy_templates/writers/plist_strings_writer.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, 3 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
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 # Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4
5
6 from grit.format.policy_templates.writers import plist_helper
7 from grit.format.policy_templates.writers import template_writer
8
9
10 def GetWriter(config):
11 '''Factory method for creating PListStringsWriter objects.
12 See the constructor of TemplateWriter for description of
13 arguments.
14 '''
15 return PListStringsWriter(['mac'], config)
16
17
18 class PListStringsWriter(template_writer.TemplateWriter):
19 '''Outputs localized string table files for the Mac policy file.
20 These files are named Localizable.strings and they are in the
21 [lang].lproj subdirectories of the manifest bundle.
22 '''
23
24 def _AddToStringTable(self, item_name, caption, desc):
25 '''Add a title and a description of an item to the string table.
26
27 Args:
28 item_name: The name of the item that will get the title and the
29 description.
30 title: The text of the title to add.
31 desc: The text of the description to add.
32 '''
33 caption = caption.replace('"', '\\"')
34 caption = caption.replace('\n', '\\n')
35 desc = desc.replace('"', '\\"')
36 desc = desc.replace('\n', '\\n')
37 self._out.append('%s.pfm_title = \"%s\";' % (item_name, caption))
38 self._out.append('%s.pfm_description = \"%s\";' % (item_name, desc))
39
40 def PreprocessPolicies(self, policy_list):
41 return self.FlattenGroupsAndSortPolicies(policy_list)
42
43 def WritePolicy(self, policy):
44 '''Add strings to the stringtable corresponding a given policy.
45
46 Args:
47 policy: The policy for which the strings will be added to the
48 string table.
49 '''
50 desc = policy['desc']
51 if policy['type'] in ('int-enum','string-enum'):
52 # Append the captions of enum items to the description string.
53 item_descs = []
54 for item in policy['items']:
55 item_descs.append(str(item['value']) + ' - ' + item['caption'])
56 desc = '\n'.join(item_descs) + '\n' + desc
57
58 self._AddToStringTable(policy['name'], policy['label'], desc)
59
60 def BeginTemplate(self):
61 app_name = plist_helper.GetPlistFriendlyName(self.config['app_name'])
62 self._AddToStringTable(
63 app_name,
64 self.config['app_name'],
65 self.messages['mac_chrome_preferences']['text'])
66
67 def Init(self):
68 # A buffer for the lines of the string table being generated.
69 self._out = []
70
71 def GetTemplateText(self):
72 return '\n'.join(self._out)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698