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

Side by Side Diff: grit/format/policy_templates/template_formatter.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
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 6
7 import os 7 import os
8 import sys 8 import sys
9 import types 9 import types
10 10
(...skipping 26 matching lines...) Expand all
37 for generating the output. If writer name is 'adm', then the class 37 for generating the output. If writer name is 'adm', then the class
38 from module 'writers.adm_writer' will be used. 38 from module 'writers.adm_writer' will be used.
39 ''' 39 '''
40 super(type(self), self).__init__() 40 super(type(self), self).__init__()
41 writer_module_name = \ 41 writer_module_name = \
42 'grit.format.policy_templates.writers.' + writer_name + '_writer' 42 'grit.format.policy_templates.writers.' + writer_name + '_writer'
43 __import__(writer_module_name) 43 __import__(writer_module_name)
44 # The module that contains the writer class: 44 # The module that contains the writer class:
45 self._writer_module = sys.modules[writer_module_name] 45 self._writer_module = sys.modules[writer_module_name]
46 46
47 def Format(self, item, lang='en', begin_item=True, output_dir='.'): 47 def Format(self, item, lang='en', output_dir='.'):
48 '''Generates a template corresponding to an <output> node in the grd file. 48 '''Generates a template corresponding to an <output> node in the grd file.
49 49
50 Args: 50 Args:
51 item: the <grit> root node of the grit tree. 51 item: the <grit> root node of the grit tree.
52 lang: the language of outputted text, e.g.: 'en' 52 lang: the language of outputted text, e.g.: 'en'
53 begin_item: True or False, depending on if this function was called at 53 begin_item: True or False, depending on if this function was called at
54 the beginning or at the end of the item. 54 the beginning or at the end of the item.
55 output_dir: The output directory, currently unused here. 55 output_dir: The output directory, currently unused here.
56 56
57 Returns: 57 Returns:
58 The text of the template file. 58 The text of the template file.
59 ''' 59 '''
60 if not begin_item:
61 return ''
62
63 self._lang = lang 60 self._lang = lang
64 self._config = writer_configuration.GetConfigurationForBuild(item.defines) 61 self._config = writer_configuration.GetConfigurationForBuild(item.defines)
65 self._policy_data = None 62 self._policy_data = None
66 self._messages = {} 63 self._messages = {}
67 self._ParseGritNodes(item) 64 self._ParseGritNodes(item)
68 return self._GetOutput() 65 return self._GetOutput()
69 66
70 def _GetOutput(self): 67 def _GetOutput(self):
71 '''Generates a template file using the instance variables initialized 68 '''Generates a template file using the instance variables initialized
72 in Format() using the writer specified in __init__(). 69 in Format() using the writer specified in __init__().
(...skipping 22 matching lines...) Expand all
95 if (isinstance(item, structure.StructureNode) and 92 if (isinstance(item, structure.StructureNode) and
96 item.attrs['type'] == 'policy_template_metafile'): 93 item.attrs['type'] == 'policy_template_metafile'):
97 assert self._policy_data == None 94 assert self._policy_data == None
98 json_text = item.gatherer.Translate( 95 json_text = item.gatherer.Translate(
99 self._lang, 96 self._lang,
100 pseudo_if_not_available=item.PseudoIsAllowed(), 97 pseudo_if_not_available=item.PseudoIsAllowed(),
101 fallback_to_english=item.ShouldFallbackToEnglish()) 98 fallback_to_english=item.ShouldFallbackToEnglish())
102 self._policy_data = eval(json_text) 99 self._policy_data = eval(json_text)
103 for child in item.children: 100 for child in item.children:
104 self._ParseGritNodes(child) 101 self._ParseGritNodes(child)
OLDNEW
« no previous file with comments | « grit/format/js_map_format.py ('k') | grit/format/policy_templates/writers/writer_unittest_common.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698