diff options
author | Markus Heiser <markus.heiser@darmarIT.de> | 2020-02-24 08:08:16 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-24 08:08:16 +0100 |
commit | 692c331b301926c04df3d09d7716aa4f719b0b34 (patch) | |
tree | b4250ec4057b5fb488965edee874cff48ca343a6 | |
parent | 09f4e2cd3138f7f19aa52c974729c791e48c20b2 (diff) | |
parent | 51e78211de5b1fcec818be089631e778bd136fc9 (diff) | |
download | searxng-692c331b301926c04df3d09d7716aa4f719b0b34.tar.gz searxng-692c331b301926c04df3d09d7716aa4f719b0b34.zip |
Merge pull request #1863 from MarcAbonce/monkey-patch-occitan-locale
Monkey patch babel get_translations to support Occitan
-rw-r--r-- | searx/webapp.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/searx/webapp.py b/searx/webapp.py index 8712cc3c1..b661e39d1 100644 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -45,6 +45,7 @@ try: from cgi import escape except: from html import escape +from six import next from datetime import datetime, timedelta from time import time from werkzeug.middleware.proxy_fix import ProxyFix @@ -52,6 +53,8 @@ from flask import ( Flask, request, render_template, url_for, Response, make_response, redirect, send_from_directory ) +from babel.support import Translations +import flask_babel from flask_babel import Babel, gettext, format_date, format_decimal from flask.json import jsonify from searx import settings, searx_dir, searx_debug @@ -156,6 +159,22 @@ _category_names = (gettext('files'), outgoing_proxies = settings['outgoing'].get('proxies') or None +_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: + 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 + + +flask_babel.get_translations = _get_translations + def _get_browser_language(request, lang_list): for lang in request.headers.get("Accept-Language", "en").split(","): @@ -180,6 +199,10 @@ def get_locale(): if locale == 'zh_TW': locale = 'zh_Hant_TW' + if locale == 'oc': + request.form['use-translation'] = 'oc' + locale = 'fr_FR' + logger.debug("selected locale is `%s`", locale) return locale |