mirror of
https://github.com/searxng/searxng.git
synced 2024-12-23 09:46:31 +00:00
[fix] remove usage of request context where not available
This commit is contained in:
parent
826ef3d009
commit
ba7c8d7b96
1 changed files with 5 additions and 6 deletions
|
@ -56,6 +56,7 @@ from flask import (
|
||||||
from babel.support import Translations
|
from babel.support import Translations
|
||||||
import flask_babel
|
import flask_babel
|
||||||
from flask_babel import Babel, gettext, format_date, format_decimal
|
from flask_babel import Babel, gettext, format_date, format_decimal
|
||||||
|
from flask.ctx import has_request_context
|
||||||
from flask.json import jsonify
|
from flask.json import jsonify
|
||||||
from searx import brand
|
from searx import brand
|
||||||
from searx import settings, searx_dir, searx_debug
|
from searx import settings, searx_dir, searx_debug
|
||||||
|
@ -165,13 +166,11 @@ _flask_babel_get_translations = flask_babel.get_translations
|
||||||
|
|
||||||
# monkey patch for flask_babel.get_translations
|
# monkey patch for flask_babel.get_translations
|
||||||
def _get_translations():
|
def _get_translations():
|
||||||
translation_locale = request.form.get('use-translation')
|
if has_request_context() and request.form.get('use-translation') == 'oc':
|
||||||
if translation_locale:
|
|
||||||
babel_ext = flask_babel.current_app.extensions['babel']
|
babel_ext = flask_babel.current_app.extensions['babel']
|
||||||
translation = Translations.load(next(babel_ext.translation_directories), 'oc')
|
return Translations.load(next(babel_ext.translation_directories), 'oc')
|
||||||
else:
|
|
||||||
translation = _flask_babel_get_translations()
|
return _flask_babel_get_translations()
|
||||||
return translation
|
|
||||||
|
|
||||||
|
|
||||||
flask_babel.get_translations = _get_translations
|
flask_babel.get_translations = _get_translations
|
||||||
|
|
Loading…
Reference in a new issue