Show More
@@ -15,11 +15,23 b'' | |||||
15 | # This program is dual-licensed. If you wish to learn more about the |
|
15 | # This program is dual-licensed. If you wish to learn more about the | |
16 | # RhodeCode Enterprise Edition, including its added features, Support services, |
|
16 | # RhodeCode Enterprise Edition, including its added features, Support services, | |
17 | # and proprietary license terms, please see https://rhodecode.com/licenses/ |
|
17 | # and proprietary license terms, please see https://rhodecode.com/licenses/ | |
18 |
|
18 | from translationstring import TranslationString | ||
19 | from pyramid.i18n import TranslationStringFactory, TranslationString |
|
|||
20 |
|
19 | |||
21 | # Create a translation string factory for the 'rhodecode' domain. |
|
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 | _ = TranslationStringFactory('rhodecode') |
|
36 | _ = TranslationStringFactory('rhodecode') | |
25 |
|
37 | |||
@@ -28,9 +40,14 b' class _LazyString(object):' | |||||
28 | def __init__(self, *args, **kw): |
|
40 | def __init__(self, *args, **kw): | |
29 | self.args = args |
|
41 | self.args = args | |
30 | self.kw = kw |
|
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 | def eval(self): |
|
49 | def eval(self): | |
33 |
req = |
|
50 | req = self._get_request() | |
34 | translator = _ |
|
51 | translator = _ | |
35 | if req: |
|
52 | if req: | |
36 | translator = req.translate |
|
53 | translator = req.translate |
General Comments 0
You need to be logged in to leave comments.
Login now