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

Side by Side Diff: grit/clique.py

Issue 9958067: Fixing a bug in GRIT where messages with substitutions would (Closed) Base URL: https://grit-i18n.googlecode.com/svn/trunk
Patch Set: 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 | « no previous file | grit/clique_unittest.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 '''Collections of messages and their translations, called cliques. Also 6 '''Collections of messages and their translations, called cliques. Also
7 collections of cliques (uber-cliques). 7 collections of cliques (uber-cliques).
8 ''' 8 '''
9 9
10 import types 10 import types
11 11
12 from grit import constants 12 from grit import constants
13 from grit import exception 13 from grit import exception
14 from grit import lazy_re
14 from grit import pseudo 15 from grit import pseudo
15 from grit import pseudo_rtl 16 from grit import pseudo_rtl
16 from grit import tclib 17 from grit import tclib
17 18
18 19
19 class UberClique(object): 20 class UberClique(object):
20 '''A factory (NOT a singleton factory) for making cliques. It has several 21 '''A factory (NOT a singleton factory) for making cliques. It has several
21 methods for working with the cliques created using the factory. 22 methods for working with the cliques created using the factory.
22 ''' 23 '''
23 24
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 translations together with their original message.''' 275 translations together with their original message.'''
275 276
276 # change this to the language code of Messages you add to cliques_. 277 # change this to the language code of Messages you add to cliques_.
277 # TODO(joi) Actually change this based on the <grit> node's source language 278 # TODO(joi) Actually change this based on the <grit> node's source language
278 source_language = 'en' 279 source_language = 'en'
279 280
280 # A constant translation we use when asked for a translation into the 281 # A constant translation we use when asked for a translation into the
281 # special language constants.CONSTANT_LANGUAGE. 282 # special language constants.CONSTANT_LANGUAGE.
282 CONSTANT_TRANSLATION = tclib.Translation(text='TTTTTT') 283 CONSTANT_TRANSLATION = tclib.Translation(text='TTTTTT')
283 284
285 # A pattern to match messages that are empty or whitespace only.
286 WHITESPACE_MESSAGE = lazy_re.compile(u'^( |\t|\n|\r|\xa0)*$')
287
284 def __init__(self, uber_clique, message, translateable=True, custom_type=None) : 288 def __init__(self, uber_clique, message, translateable=True, custom_type=None) :
285 '''Create a new clique initialized with just a message. 289 '''Create a new clique initialized with just a message.
286 290
291 Note that messages with a body comprised only of whitespace will implicitly
292 be marked non-translatable.
293
287 Args: 294 Args:
288 uber_clique: Our uber-clique (collection of cliques) 295 uber_clique: Our uber-clique (collection of cliques)
289 message: tclib.Message() 296 message: tclib.Message()
290 translateable: True | False 297 translateable: True | False
291 custom_type: instance of clique.CustomType interface 298 custom_type: instance of clique.CustomType interface
292 ''' 299 '''
293 # Our parent 300 # Our parent
294 self.uber_clique = uber_clique 301 self.uber_clique = uber_clique
295 # If not translateable, we only store the original message. 302 # If not translateable, we only store the original message.
296 self.translateable = translateable 303 self.translateable = translateable
304
305 # We implicitly mark messages that have a whitespace-only body as
306 # non-translateable.
307 if MessageClique.WHITESPACE_MESSAGE.match(message.GetRealContent()):
308 self.translateable = False
309
297 # A mapping of language identifiers to tclib.BaseMessage and its 310 # A mapping of language identifiers to tclib.BaseMessage and its
298 # subclasses (i.e. tclib.Message and tclib.Translation). 311 # subclasses (i.e. tclib.Message and tclib.Translation).
299 self.clique = { MessageClique.source_language : message } 312 self.clique = { MessageClique.source_language : message }
300 # A list of the "shortcut groups" this clique is 313 # A list of the "shortcut groups" this clique is
301 # part of. Within any given shortcut group, no shortcut key (e.g. &J) 314 # part of. Within any given shortcut group, no shortcut key (e.g. &J)
302 # must appear more than once in each language for all cliques that 315 # must appear more than once in each language for all cliques that
303 # belong to the group. 316 # belong to the group.
304 self.shortcut_groups = [] 317 self.shortcut_groups = []
305 # An instance of the CustomType interface, or None. If this is set, it will 318 # An instance of the CustomType interface, or None. If this is set, it will
306 # be used to validate the original message and translations thereof, and 319 # be used to validate the original message and translations thereof, and
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 transl_msg = tclib.Translation(id=self.GetId(), 451 transl_msg = tclib.Translation(id=self.GetId(),
439 text=translation.GetPresentableContent(), 452 text=translation.GetPresentableContent(),
440 placeholders=original.GetPlaceholders()) 453 placeholders=original.GetPlaceholders())
441 454
442 if self.custom_type and not self.custom_type.ValidateAndModify(language, tra nsl_msg): 455 if self.custom_type and not self.custom_type.ValidateAndModify(language, tra nsl_msg):
443 print "WARNING: %s translation failed validation: %s" % ( 456 print "WARNING: %s translation failed validation: %s" % (
444 language, transl_msg.GetId()) 457 language, transl_msg.GetId())
445 458
446 self.clique[language] = transl_msg 459 self.clique[language] = transl_msg
447 460
OLDNEW
« no previous file with comments | « no previous file | grit/clique_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698