##// END OF EJS Templates
translations: fixed code for python3 and gevent imports of threadglobals
super-admin -
r5043:6f1c6b4c default
parent child Browse files
Show More
@@ -15,11 +15,23 b''
15 15 # This program is dual-licensed. If you wish to learn more about the
16 16 # RhodeCode Enterprise Edition, including its added features, Support services,
17 17 # and proprietary license terms, please see https://rhodecode.com/licenses/
18
19 from pyramid.i18n import TranslationStringFactory, TranslationString
18 from translationstring import TranslationString
20 19
21 20 # Create a translation string factory for the 'rhodecode' domain.
22 from pyramid.threadlocal import get_current_request
21 # This is extracted from pyramid.i18n and uses its code to be gevent safe
22
23 def TranslationStringFactory(factory_domain): # noqa
24
25 def create(msgid, mapping=None, default=None, context=None):
26 if isinstance(msgid, TranslationString):
27 domain = msgid.domain or factory_domain
28 else:
29 domain = factory_domain
30
31 return TranslationString(msgid, domain=domain, default=default,
32 mapping=mapping, context=context)
33 return create
34
23 35
24 36 _ = TranslationStringFactory('rhodecode')
25 37
@@ -28,9 +40,14 b' class _LazyString(object):'
28 40 def __init__(self, *args, **kw):
29 41 self.args = args
30 42 self.kw = kw
43 self._request = kw.pop('request', None)
44
45 def _get_request(self):
46 from pyramid.threadlocal import get_current_request
47 return self._request or get_current_request()
31 48
32 49 def eval(self):
33 req = get_current_request()
50 req = self._get_request()
34 51 translator = _
35 52 if req:
36 53 translator = req.translate
General Comments 0
You need to be logged in to leave comments. Login now