# HG changeset patch # User RhodeCode Admin # Date 2023-07-18 07:41:28 # Node ID 6f1c6b4c2f35a68ba6971a9bcb6232e964ff6e51 # Parent 4c5af7994776a75847ff60c0b729265c2e6f32ed translations: fixed code for python3 and gevent imports of threadglobals diff --git a/rhodecode/translation.py b/rhodecode/translation.py --- a/rhodecode/translation.py +++ b/rhodecode/translation.py @@ -15,11 +15,23 @@ # This program is dual-licensed. If you wish to learn more about the # RhodeCode Enterprise Edition, including its added features, Support services, # and proprietary license terms, please see https://rhodecode.com/licenses/ - -from pyramid.i18n import TranslationStringFactory, TranslationString +from translationstring import TranslationString # Create a translation string factory for the 'rhodecode' domain. -from pyramid.threadlocal import get_current_request +# This is extracted from pyramid.i18n and uses its code to be gevent safe + +def TranslationStringFactory(factory_domain): # noqa + + def create(msgid, mapping=None, default=None, context=None): + if isinstance(msgid, TranslationString): + domain = msgid.domain or factory_domain + else: + domain = factory_domain + + return TranslationString(msgid, domain=domain, default=default, + mapping=mapping, context=context) + return create + _ = TranslationStringFactory('rhodecode') @@ -28,9 +40,14 @@ class _LazyString(object): def __init__(self, *args, **kw): self.args = args self.kw = kw + self._request = kw.pop('request', None) + + def _get_request(self): + from pyramid.threadlocal import get_current_request + return self._request or get_current_request() def eval(self): - req = get_current_request() + req = self._get_request() translator = _ if req: translator = req.translate