Edgewall Software

Changeset 61


Ignore:
Timestamp:
06/08/07 13:44:28 (5 years ago)
Author:
cmlenz
Message:

Fix typo in [58].

Location:
trunk/babel
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/babel/messages/__init__.py

    r57 r61  
    1414"""Support for ``gettext`` message catalogs.""" 
    1515 
    16 import gettext 
    17  
    18 __all__ = ['Translations'] 
    19 __docformat__ = 'restructuredtext en' 
    20  
    21 DEFAULT_DOMAIN = 'messages' 
    22  
    23  
    24 class Translations(gettext.GNUTranslations): 
    25     """An extended translation catalog class.""" 
    26  
    27     def __init__(self, fileobj=None): 
    28         """Initialize the translations catalog. 
    29          
    30         :param fileobj: the file-like object the translation should be read 
    31                         from 
    32         """ 
    33         gettext.GNUTranslations.__init__(self, fp=fileobj) 
    34         self.files = [getattr(fileobj, 'name')] 
    35  
    36     def load(cls, dirname=None, locales=None, domain=DEFAULT_DOMAIN): 
    37         """Load translations from the given directory. 
    38          
    39         :param dirname: the directory containing the ``MO`` files 
    40         :param locales: the list of locales in order of preference (items in 
    41                         this list can be either `Locale` objects or locale 
    42                         strings) 
    43         :param domain: the message domain 
    44         :return: the loaded catalog, or a ``NullTranslations`` instance if no 
    45                  matching translations were found 
    46         :rtype: `Translations` 
    47         """ 
    48         if not isinstance(locales, (list, tuple)): 
    49             locales = [locales] 
    50         locales = [str(locale) for locale in locales] 
    51         filename = gettext.find(domain, dirname, locales) 
    52         if not filename: 
    53             return gettext.NullTranslations() 
    54         return cls(fileobj=open(filename, 'rb')) 
    55     load = classmethod(load) 
    56  
    57     def merge(self, translations): 
    58         """Merge the given translations into the catalog. 
    59          
    60         Message translations in the specfied catalog override any messages with 
    61         the same identifier in the existing catalog. 
    62          
    63         :param translations: the `Translations` instance with the messages to 
    64                              merge 
    65         :return: the `Translations` instance (``self``) so that `merge` calls 
    66                  can be easily chained 
    67         :rtype: `Translations` 
    68         """ 
    69         if isinstance(translations, Translations): 
    70             self._catalog.update(translations._catalog) 
    71             self.files.extend(translations.files) 
    72         return self 
    73  
    74     def __repr__(self): 
    75         return "<%s %r>" % (type(self).__name__) 
     16from babel.messages.catalog import * 
  • trunk/babel/tests/__init__.py

    r55 r61  
    2121    suite.addTest(dates.suite()) 
    2222    suite.addTest(localedata.suite()) 
     23    suite.addTest(messages.suite()) 
    2324    suite.addTest(numbers.suite()) 
     25    suite.addTest(support.suite()) 
    2426    suite.addTest(util.suite()) 
    25     suite.addTest(messages.suite()) 
    2627    return suite 
    2728 
  • trunk/babel/util.py

    r57 r61  
    1818import re 
    1919 
    20 __all__ = ['pathmatch', 'relpath', 'LazyProxy', 'UTC'] 
     20__all__ = ['pathmatch', 'relpath', 'UTC'] 
    2121__docformat__ = 'restructuredtext en' 
    2222 
     
    117117 
    118118 
    119 class LazyProxy(object): 
    120     """Class for proxy objects that delegate to a specified function to evaluate 
    121     the actual object. 
    122      
    123     >>> def greeting(name='world'): 
    124     ...     return 'Hello, %s!' % name 
    125     >>> lazy_greeting = LazyProxy(greeting, name='Joe') 
    126     >>> print lazy_greeting 
    127     Hello, Joe! 
    128     >>> u'  ' + lazy_greeting 
    129     u'  Hello, Joe!' 
    130     >>> u'(%s)' % lazy_greeting 
    131     u'(Hello, Joe!)' 
    132      
    133     This can be used, for example, to implement lazy translation functions that 
    134     delay the actual translation until the string is actually used. The 
    135     rationale for such behavior is that the locale of the user may not always 
    136     be available. In web applications, you only know the locale when processing 
    137     a request. 
    138      
    139     The proxy implementation attempts to be as complete as possible, so that 
    140     the lazy objects should mostly work as expected, for example for sorting: 
    141      
    142     >>> greetings = [ 
    143     ...     LazyProxy(greeting, 'world'), 
    144     ...     LazyProxy(greeting, 'Joe'), 
    145     ...     LazyProxy(greeting, 'universe'), 
    146     ... ] 
    147     >>> greetings.sort() 
    148     >>> for greeting in greetings: 
    149     ...     print greeting 
    150     Hello, Joe! 
    151     Hello, universe! 
    152     Hello, world! 
    153     """ 
    154     __slots__ = ['_func', '_args', '_kwargs', '_value'] 
    155  
    156     def __init__(self, func, *args, **kwargs): 
    157         # Avoid triggering our own __setattr__ implementation 
    158         object.__setattr__(self, '_func', func) 
    159         object.__setattr__(self, '_args', args) 
    160         object.__setattr__(self, '_kwargs', kwargs) 
    161         object.__setattr__(self, '_value', None) 
    162  
    163     def value(self): 
    164         if self._value is None: 
    165             value = self._func(*self._args, **self._kwargs) 
    166             object.__setattr__(self, '_value', value) 
    167         return self._value 
    168     value = property(value) 
    169  
    170     def __contains__(self, key): 
    171         return key in self.value 
    172  
    173     def __nonzero__(self): 
    174         return bool(self.value) 
    175  
    176     def __dir__(self): 
    177         return dir(self.value) 
    178  
    179     def __iter__(self): 
    180         return iter(self.value) 
    181  
    182     def __len__(self): 
    183         return len(self.value) 
    184  
    185     def __str__(self): 
    186         return str(self.value) 
    187  
    188     def __unicode__(self): 
    189         return unicode(self.value) 
    190  
    191     def __add__(self, other): 
    192         return self.value + other 
    193  
    194     def __radd__(self, other): 
    195         return other + self.value 
    196  
    197     def __mod__(self, other): 
    198         return self.value % other 
    199  
    200     def __rmod__(self, other): 
    201         return other % self.value 
    202  
    203     def __mul__(self, other): 
    204         return self.value * other 
    205  
    206     def __rmul__(self, other): 
    207         return other * self.value 
    208  
    209     def __call__(self, *args, **kwargs): 
    210         return self.value(*args, **kwargs) 
    211  
    212     def __lt__(self, other): 
    213         return self.value < other 
    214  
    215     def __le__(self, other): 
    216         return self.value <= other 
    217  
    218     def __eq__(self, other): 
    219         return self.value == other 
    220  
    221     def __ne__(self, other): 
    222         return self.value != other 
    223  
    224     def __gt__(self, other): 
    225         return self.value > other 
    226  
    227     def __ge__(self, other): 
    228         return self.value >= other 
    229  
    230     def __delattr__(self, name): 
    231         delattr(self.value, name) 
    232  
    233     def __getattr__(self, name): 
    234         return getattr(self.value, name) 
    235  
    236     def __setattr__(self, key, value): 
    237         setattr(self.value, name, value) 
    238  
    239     def __delitem__(self, key): 
    240         del self.value[key] 
    241  
    242     def __getitem__(self, key): 
    243         return self.value[key] 
    244  
    245     def __setitem__(self, key, value): 
    246         self.value[name] = value 
    247  
    248  
    249119try: 
    250120    relpath = os.path.relpath 
Note: See TracChangeset for help on using the changeset viewer.