diff options
| author | Markus Heiser <markus.heiser@darmarIT.de> | 2020-04-20 12:44:50 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-04-20 12:44:50 +0000 |
| commit | 9302d1fc170a7d2c09fba8c34a75edc8f8652c9a (patch) | |
| tree | 9c952ada2c5510f0838d018250d1cb5197d77935 /searx/webapp.py | |
| parent | 3a26093c46469a320c2dfa4d732634a462c8f0f4 (diff) | |
| parent | 0b7e7acf741a97ae47f809956614df1ea45326e4 (diff) | |
Merge branch 'master' into master
Diffstat (limited to 'searx/webapp.py')
| -rwxr-xr-x | searx/webapp.py | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/searx/webapp.py b/searx/webapp.py index c910230ab..8c3531069 100755 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -56,6 +56,7 @@ from flask import ( from babel.support import Translations import flask_babel from flask_babel import Babel, gettext, format_date, format_decimal +from flask.ctx import has_request_context from flask.json import jsonify from searx import brand 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 def _get_translations(): - translation_locale = request.form.get('use-translation') - if translation_locale: + if has_request_context() and request.form.get('use-translation') == 'oc': babel_ext = flask_babel.current_app.extensions['babel'] - translation = Translations.load(next(babel_ext.translation_directories), 'oc') - else: - translation = _flask_babel_get_translations() - return translation + return Translations.load(next(babel_ext.translation_directories), 'oc') + + return _flask_babel_get_translations() flask_babel.get_translations = _get_translations @@ -627,7 +626,7 @@ def index(): 'corrections': list(result_container.corrections), 'infoboxes': result_container.infoboxes, 'suggestions': list(result_container.suggestions), - 'unresponsive_engines': list(result_container.unresponsive_engines)}, + 'unresponsive_engines': __get_translated_errors(result_container.unresponsive_engines)}, # noqa default=lambda item: list(item) if isinstance(item, set) else item), mimetype='application/json') elif output_format == 'csv': @@ -695,7 +694,7 @@ def index(): corrections=correction_urls, infoboxes=result_container.infoboxes, paging=result_container.paging, - unresponsive_engines=result_container.unresponsive_engines, + unresponsive_engines=__get_translated_errors(result_container.unresponsive_engines), current_language=match_language(search_query.lang, LANGUAGE_CODES, fallback=request.preferences.get_value("language")), @@ -706,6 +705,16 @@ def index(): ) +def __get_translated_errors(unresponsive_engines): + translated_errors = [] + for unresponsive_engine in unresponsive_engines: + error_msg = gettext(unresponsive_engine[1]) + if unresponsive_engine[2]: + error_msg = "{} {}".format(error_msg, unresponsive_engine[2]) + translated_errors.append((unresponsive_engine[0], error_msg)) + return translated_errors + + @app.route('/about', methods=['GET']) def about(): """Render about page""" |