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

Side by Side Diff: grit/clique.py

Issue 1410023007: Skip missing translations when generating JSON resources. (Closed) Base URL: https://chromium.googlesource.com/external/grit-i18n.git@master
Patch Set: Created 5 years, 1 month 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
« no previous file with comments | « no previous file | grit/format/chrome_messages_json.py » ('j') | grit/format/chrome_messages_json.py » ('J')
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 re 10 import re
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 self.shortcut_groups.append(group) 358 self.shortcut_groups.append(group)
359 359
360 def SetCustomType(self, custom_type): 360 def SetCustomType(self, custom_type):
361 '''Makes this clique use custom_type for validating messages and 361 '''Makes this clique use custom_type for validating messages and
362 translations, and optionally modifying translations. 362 translations, and optionally modifying translations.
363 ''' 363 '''
364 self.custom_type = custom_type 364 self.custom_type = custom_type
365 if custom_type and not custom_type.Validate(self.GetMessage()): 365 if custom_type and not custom_type.Validate(self.GetMessage()):
366 raise exception.InvalidMessage(self.GetMessage().GetRealContent()) 366 raise exception.InvalidMessage(self.GetMessage().GetRealContent())
367 367
368 def MessageForLanguage(self, lang, pseudo_if_no_match=True, fallback_to_englis h=False): 368 def MessageForLanguage(self, lang, pseudo_if_no_match=True,
369 fallback_to_english=False, none_if_no_match=False):
Jamie 2015/10/27 19:25:13 Optional: AFAICT, the final three parameters to th
Sergey Ulanov 2016/02/06 01:03:17 The existing two flags are specified as booleans i
369 '''Returns the message/translation for the specified language, providing 370 '''Returns the message/translation for the specified language, providing
370 a pseudotranslation if there is no available translation and a pseudo- 371 a pseudotranslation if there is no available translation and a pseudo-
371 translation is requested. 372 translation is requested.
372 373
373 The translation of any message whatsoever in the special language 374 The translation of any message whatsoever in the special language
374 'x_constant' is the message "TTTTTT". 375 'x_constant' is the message "TTTTTT".
375 376
376 Args: 377 Args:
377 lang: 'en' 378 lang: 'en'
378 pseudo_if_no_match: True 379 pseudo_if_no_match: True
379 fallback_to_english: False 380 fallback_to_english: False
381 none_if_no_match: False
380 382
381 Return: 383 Return:
382 tclib.BaseMessage 384 tclib.BaseMessage
383 ''' 385 '''
384 if not self.translateable: 386 if not self.translateable:
385 return self.GetMessage() 387 return self.GetMessage()
386 388
387 if lang == constants.CONSTANT_LANGUAGE: 389 if lang == constants.CONSTANT_LANGUAGE:
388 return self.CONSTANT_TRANSLATION 390 return self.CONSTANT_TRANSLATION
389 391
390 for msglang in self.clique.keys(): 392 for msglang in self.clique.keys():
391 if lang == msglang: 393 if lang == msglang:
392 return self.clique[msglang] 394 return self.clique[msglang]
393 395
394 if lang == constants.FAKE_BIDI: 396 if lang == constants.FAKE_BIDI:
395 return pseudo_rtl.PseudoRTLMessage(self.GetMessage()) 397 return pseudo_rtl.PseudoRTLMessage(self.GetMessage())
396 398
397 if fallback_to_english: 399 if fallback_to_english:
398 self.uber_clique._AddMissingTranslation(lang, self, is_error=False) 400 self.uber_clique._AddMissingTranslation(lang, self, is_error=False)
399 return self.GetMessage() 401 return self.GetMessage()
400 402
401 # If we're not supposed to generate pseudotranslations, we add an error 403 # If we're not supposed to generate pseudotranslations, we add an error
402 # report to a list of errors, then fail at a higher level, so that we 404 # report to a list of errors, then fail at a higher level, so that we
403 # get a list of all messages that are missing translations. 405 # get a list of all messages that are missing translations.
Jamie 2015/10/27 19:25:13 This comment is a bit misleading now that there's
Sergey Ulanov 2016/02/06 01:03:17 Done.
404 if not pseudo_if_no_match: 406 if pseudo_if_no_match:
405 self.uber_clique._AddMissingTranslation(lang, self, is_error=True) 407 return pseudo.PseudoMessage(self.GetMessage())
406 408
409 if none_if_no_match:
410 return None
411
412 self.uber_clique._AddMissingTranslation(lang, self, is_error=True)
407 return pseudo.PseudoMessage(self.GetMessage()) 413 return pseudo.PseudoMessage(self.GetMessage())
408 414
409 def AllMessagesThatMatch(self, lang_re, include_pseudo = True): 415 def AllMessagesThatMatch(self, lang_re, include_pseudo = True):
410 '''Returns a map of all messages that match 'lang', including the pseudo 416 '''Returns a map of all messages that match 'lang', including the pseudo
411 translation if requested. 417 translation if requested.
412 418
413 Args: 419 Args:
414 lang_re: re.compile('fr|en') 420 lang_re: re.compile('fr|en')
415 include_pseudo: True 421 include_pseudo: True
416 422
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 transl_msg = tclib.Translation(id=self.GetId(), 480 transl_msg = tclib.Translation(id=self.GetId(),
475 text=translation.GetPresentableContent(), 481 text=translation.GetPresentableContent(),
476 placeholders=original.GetPlaceholders()) 482 placeholders=original.GetPlaceholders())
477 483
478 if self.custom_type and not self.custom_type.ValidateAndModify(language, tra nsl_msg): 484 if self.custom_type and not self.custom_type.ValidateAndModify(language, tra nsl_msg):
479 print "WARNING: %s translation failed validation: %s" % ( 485 print "WARNING: %s translation failed validation: %s" % (
480 language, transl_msg.GetId()) 486 language, transl_msg.GetId())
481 487
482 self.clique[language] = transl_msg 488 self.clique[language] = transl_msg
483 489
OLDNEW
« no previous file with comments | « no previous file | grit/format/chrome_messages_json.py » ('j') | grit/format/chrome_messages_json.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698