Changeset d7b4ae in indico
- Timestamp:
- 08/01/11 18:01:56 (22 months ago)
- Branches:
- master, hello-world-walkthrough, ipv6, v0.98-series, v0.98.2, v0.98.3, v0.98b2, v0.99, 051b2622c51afb171a1dedb46a0df4fbb0cbd02e, 4c7d4152dff271ba5df5a8606605969cab454080
- Children:
- 0d631e0
- Parents:
- 6c87d3
- git-author:
- Pedro Ferreira <jose.pedro.ferreira@…> (08/01/11 17:14:22)
- git-committer:
- Pedro Ferreira <jose.pedro.ferreira@…> (08/01/11 18:01:56)
- Location:
- indico/util
- Files:
-
- 2 edited
-
i18n.py (modified) (1 diff)
-
translations.py (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
indico/util/i18n.py
r331c68 rd7b4ae 37 37 ngettext = ungettext = lazyTranslations.ungettext 38 38 39 except: 39 gettext_lazy = forceLazyTranslations.ugettext 40 41 except ImportError: 40 42 # no Babel 41 43 pass -
indico/util/translations.py
ra346fb rd7b4ae 20 20 21 21 22 from babel.support import Translations, LazyProxy 22 from babel.support import Translations, LazyProxy as _LazyProxy 23 23 from babel.core import Locale 24 24 from gettext import NullTranslations … … 30 30 nullTranslations = NullTranslations() 31 31 32 33 class LazyProxy(_LazyProxy): 34 """ 35 Stateless version of Babel's LazyProxy 36 """ 37 def value(self): 38 # just return 39 return self._func(*self._args, **self._kwargs) 40 value = property(value) 32 41 33 42 … … 45 54 def _tr_eval(func, *args, **kwargs): 46 55 # ok, eval time... is there a translation? 56 47 57 if 'translation' in ContextManager.get(): 48 58 # yes? good, let's do it 49 59 tr = ContextManager.get('translation') 50 60 else: 51 # no? too bad, just don't trans ate anything61 # no? too bad, just don't translate anything 52 62 tr = nullTranslations 53 return getattr(tr, func)(*args, **kwargs).encode('utf-8') 63 res = getattr(tr, func)(*args, **kwargs).encode('utf-8') 64 return res 54 65 55 66 … … 59 70 It will be then done when the value is finally used 60 71 """ 72 73 def __init__(self, forceLazy=False): 74 self.force = forceLazy 75 super(LazyTranslations, self).__init__() 76 61 77 def _wrapper(self, func, *args, **kwargs): 62 # if there is a locale already defined 63 if 'translation' in ContextManager.get(): 78 # if there is a locale already defined, use it 79 # (unless we have forced "lazy mode") 80 if 'translation' in ContextManager.get() and not self.force: 64 81 # straight translation 65 82 translation = ContextManager.get('translation') … … 77 94 78 95 lazyTranslations = LazyTranslations() 96 forceLazyTranslations = LazyTranslations(forceLazy=True) 79 97 lazyTranslations.install(unicode=True)
Note: See TracChangeset
for help on using the changeset viewer.
