summaryrefslogtreecommitdiff
path: root/searx/webapp.py
diff options
context:
space:
mode:
Diffstat (limited to 'searx/webapp.py')
-rw-r--r--searx/webapp.py22
1 files changed, 11 insertions, 11 deletions
diff --git a/searx/webapp.py b/searx/webapp.py
index a856c07dd..8712cc3c1 100644
--- a/searx/webapp.py
+++ b/searx/webapp.py
@@ -157,14 +157,16 @@ _category_names = (gettext('files'),
outgoing_proxies = settings['outgoing'].get('proxies') or None
+def _get_browser_language(request, lang_list):
+ for lang in request.headers.get("Accept-Language", "en").split(","):
+ locale = match_language(lang, lang_list, fallback=None)
+ if locale is not None:
+ return locale
+
+
@babel.localeselector
def get_locale():
- locale = "en-US"
-
- for lang in request.headers.get("Accept-Language", locale).split(","):
- locale = match_language(lang, settings['locales'].keys(), fallback=None)
- if locale is not None:
- break
+ locale = _get_browser_language(request, settings['locales'].keys())
logger.debug("default locale from browser info is `%s`", locale)
@@ -372,8 +374,7 @@ def render(template_name, override_theme=None, **kwargs):
kwargs['language_codes'] = languages
if 'current_language' not in kwargs:
kwargs['current_language'] = match_language(request.preferences.get_value('language'),
- LANGUAGE_CODES,
- fallback=locale)
+ LANGUAGE_CODES)
# override url_for function in templates
kwargs['url_for'] = url_for_theme
@@ -444,11 +445,10 @@ def pre_request():
request.errors.append(gettext('Invalid settings'))
# init search language and locale
- locale = get_locale()
if not preferences.get_value("language"):
- preferences.parse_dict({"language": locale})
+ preferences.parse_dict({"language": _get_browser_language(request, LANGUAGE_CODES)})
if not preferences.get_value("locale"):
- preferences.parse_dict({"locale": locale})
+ preferences.parse_dict({"locale": get_locale()})
# request.user_plugins
request.user_plugins = []