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

Side by Side Diff: grit/node/io.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
« no previous file with comments | « grit/node/include.py ('k') | grit/node/io_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 # Copyright (c) 2006-2008 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 '''The <output> and <file> elements.
7 '''
8
9 import os
10 import re
11 import grit.format.rc_header
12
13 from grit.node import base
14 from grit import exception
15 from grit import util
16 from grit import xtb_reader
17
18
19 class FileNode(base.Node):
20 '''A <file> element.'''
21
22 def __init__(self):
23 super(type(self), self).__init__()
24 self.re = None
25 self.should_load_ = True
26
27 def IsTranslation(self):
28 return True
29
30 def GetLang(self):
31 return self.attrs['lang']
32
33 def DisableLoading(self):
34 self.should_load_ = False
35
36 def MandatoryAttributes(self):
37 return ['path', 'lang']
38
39 def RunGatherers(self, recursive=False, debug=False):
40 if not self.should_load_ or not self.SatisfiesOutputCondition():
41 return
42
43 root = self.GetRoot()
44 defs = {}
45 if hasattr(root, 'defines'):
46 defs = root.defines
47
48 xtb_file = file(self.GetFilePath())
49 try:
50 lang = xtb_reader.Parse(xtb_file,
51 self.UberClique().GenerateXtbParserCallback(
52 self.attrs['lang'], debug=debug),
53 defs=defs)
54 except:
55 print "Exception during parsing of %s" % self.GetFilePath()
56 raise
57 # We special case 'he' and 'iw' because the translation console uses 'iw'
58 # and we use 'he'.
59 assert (lang == self.attrs['lang'] or
60 (lang == 'iw' and self.attrs['lang'] == 'he')), ('The XTB file you '
61 'reference must contain messages in the language specified\n'
62 'by the \'lang\' attribute.')
63
64 def GetFilePath(self):
65 return self.ToRealPath(os.path.expandvars(self.attrs['path']))
66
67
68 class OutputNode(base.Node):
69 '''An <output> element.'''
70
71 def MandatoryAttributes(self):
72 return ['filename', 'type']
73
74 def DefaultAttributes(self):
75 return { 'lang' : '', # empty lang indicates all languages
76 'language_section' : 'neutral' # defines a language neutral section
77 }
78
79 def GetType(self):
80 return self.attrs['type']
81
82 def GetLanguage(self):
83 '''Returns the language ID, default 'en'.'''
84 return self.attrs['lang']
85
86 def GetFilename(self):
87 return self.attrs['filename']
88
89 def GetOutputFilename(self):
90 if hasattr(self, 'output_filename'):
91 return self.output_filename
92 else:
93 return self.attrs['filename']
94
95 def _IsValidChild(self, child):
96 return isinstance(child, EmitNode)
97
98 class EmitNode(base.ContentNode):
99 ''' An <emit> element.'''
100
101 def DefaultAttributes(self):
102 return { 'emit_type' : 'prepend'}
103
104 def GetEmitType(self):
105 '''Returns the emit_type for this node. Default is 'append'.'''
106 return self.attrs['emit_type']
107
108 def ItemFormatter(self, t):
109 if t == 'rc_header':
110 return grit.format.rc_header.EmitAppender()
111 else:
112 return super(type(self), self).ItemFormatter(t)
113
114
115
OLDNEW
« no previous file with comments | « grit/node/include.py ('k') | grit/node/io_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698