Skip to content

Commit

Permalink
[#4801] Don't use pylons to get language outside a request
Browse files Browse the repository at this point in the history
  • Loading branch information
amercader committed Dec 20, 2019
1 parent c2ba941 commit 8c913e2
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions ckan/lib/i18n.py
Expand Up @@ -49,15 +49,14 @@
UnknownLocaleError)
from babel.support import Translations
import polib
import six

from ckan.common import config, is_flask_request, aslist
import ckan.i18n
from ckan.plugins import PluginImplementations
from ckan.plugins.interfaces import ITranslation

if six.PY2:
from pylons import i18n
from pylons import i18n as pylons_i18n
import pylons


Expand Down Expand Up @@ -228,9 +227,9 @@ def _set_lang(lang):
if config.get('ckan.i18n_directory'):
fake_config = {'pylons.paths': {'root': config['ckan.i18n_directory']},
'pylons.package': config['pylons.package']}
i18n.set_lang(lang, pylons_config=fake_config, class_=Translations)
pylons_i18n.set_lang(lang, pylons_config=fake_config, class_=Translations)
else:
i18n.set_lang(lang, class_=Translations)
pylons_i18n.set_lang(lang, class_=Translations)


def handle_request(request, tmpl_context):
Expand Down Expand Up @@ -279,10 +278,6 @@ def get_lang():
if is_flask_request():
from ckan.config.middleware.flask_app import get_locale
return get_locale()
else:
langs = i18n.get_lang()
if langs:
return langs[0]
return 'en'


Expand Down

0 comments on commit 8c913e2

Please sign in to comment.