OLD | NEW |
(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 '''Interface for all gatherers. |
| 7 ''' |
| 8 |
| 9 |
| 10 from grit import clique |
| 11 |
| 12 |
| 13 class GathererBase(object): |
| 14 '''Interface for all gatherer implementations. Subclasses must implement |
| 15 all methods that raise NotImplemented.''' |
| 16 |
| 17 def __init__(self): |
| 18 # A default uberclique that is local to this object. Users can override |
| 19 # this with the uberclique they are using. |
| 20 self.uberclique = clique.UberClique() |
| 21 # Indicates whether this gatherer is a skeleton gatherer, in which case |
| 22 # we should not do some types of processing on the translateable bits. |
| 23 self.is_skeleton = False |
| 24 |
| 25 def SetUberClique(self, uberclique): |
| 26 '''Overrides the default uberclique so that cliques created by this object |
| 27 become part of the uberclique supplied by the user. |
| 28 ''' |
| 29 self.uberclique = uberclique |
| 30 |
| 31 def SetSkeleton(self, is_skeleton): |
| 32 self.is_skeleton = is_skeleton |
| 33 |
| 34 def IsSkeleton(self): |
| 35 return self.is_skeleton |
| 36 |
| 37 def Parse(self): |
| 38 '''Parses the contents of what is being gathered.''' |
| 39 raise NotImplementedError() |
| 40 |
| 41 def GetText(self): |
| 42 '''Returns the text of what is being gathered.''' |
| 43 raise NotImplementedError() |
| 44 |
| 45 def GetTextualIds(self): |
| 46 '''Returns the mnemonic IDs that need to be defined for the resource |
| 47 being gathered to compile correctly.''' |
| 48 return [] |
| 49 |
| 50 def GetCliques(self): |
| 51 '''Returns the MessageClique objects for all translateable portions.''' |
| 52 return [] |
| 53 |
| 54 def Translate(self, lang, pseudo_if_not_available=True, |
| 55 skeleton_gatherer=None, fallback_to_english=False): |
| 56 '''Returns the resource being gathered, with translateable portions filled |
| 57 with the translation for language 'lang'. |
| 58 |
| 59 If pseudo_if_not_available is true, a pseudotranslation will be used for any |
| 60 message that doesn't have a real translation available. |
| 61 |
| 62 If no translation is available and pseudo_if_not_available is false, |
| 63 fallback_to_english controls the behavior. If it is false, throw an error. |
| 64 If it is true, use the English version of the message as its own |
| 65 "translation". |
| 66 |
| 67 If skeleton_gatherer is specified, the translation will use the nontranslate
able |
| 68 parts from the gatherer 'skeleton_gatherer', which must be of the same type |
| 69 as 'self'. |
| 70 |
| 71 If fallback_to_english |
| 72 |
| 73 Args: |
| 74 lang: 'en' |
| 75 pseudo_if_not_available: True | False |
| 76 skeleton_gatherer: other_gatherer |
| 77 fallback_to_english: True | False |
| 78 |
| 79 Return: |
| 80 e.g. 'ID_THIS_SECTION TYPE\n...BEGIN\n "Translated message"\n......\nEND' |
| 81 |
| 82 Raises: |
| 83 grit.exception.NotReady() if used before Parse() has been successfully |
| 84 called. |
| 85 grit.exception.NoSuchTranslation() if 'pseudo_if_not_available' and |
| 86 fallback_to_english are both false and there is no translation for the |
| 87 requested language. |
| 88 ''' |
| 89 raise NotImplementedError() |
| 90 |
| 91 def FromFile(rc_file, extkey=None, encoding = 'cp1252'): |
| 92 '''Loads the resource from the file 'rc_file'. Optionally an external key |
| 93 (which gets passed to the gatherer's constructor) can be specified. |
| 94 |
| 95 If 'rc_file' is a filename, it will be opened for reading using 'encoding'. |
| 96 Otherwise the 'encoding' parameter is ignored. |
| 97 |
| 98 Args: |
| 99 rc_file: file('') | 'filename.rc' |
| 100 extkey: e.g. 'ID_MY_DIALOG' |
| 101 encoding: 'utf-8' |
| 102 |
| 103 Return: |
| 104 grit.gather.interface.GathererBase subclass |
| 105 ''' |
| 106 raise NotImplementedError() |
| 107 FromFile = staticmethod(FromFile) |
| 108 |
OLD | NEW |