summaryrefslogtreecommitdiff
path: root/searx
diff options
context:
space:
mode:
authorMarkus Heiser <markus.heiser@darmarIT.de>2020-02-23 11:47:49 +0000
committerGitHub <noreply@github.com>2020-02-23 11:47:49 +0000
commit98322ac15c219c1bb61a3528543c785f32c9a697 (patch)
tree01b461cccb2296043fc323a55ed2fd5e51aaf5d1 /searx
parente1b60106b7dab37fe29cb68c9b625c5fe52c1385 (diff)
parent90d23e7ef6666408e4ad49841e89ca086568e5b1 (diff)
Merge branch 'master' into engine-etools
Diffstat (limited to 'searx')
-rw-r--r--searx/preferences.py7
-rw-r--r--searx/settings.yml1
-rw-r--r--searx/templates/__common__/about.html2
-rw-r--r--searx/templates/oscar/base.html2
-rw-r--r--searx/templates/simple/base.html2
-rw-r--r--searx/webapp.py22
6 files changed, 21 insertions, 15 deletions
diff --git a/searx/preferences.py b/searx/preferences.py
index 669232b12..6e31aa187 100644
--- a/searx/preferences.py
+++ b/searx/preferences.py
@@ -4,6 +4,7 @@ from sys import version
from searx import settings, autocomplete
from searx.languages import language_codes as languages
+from searx.utils import match_language
from searx.url_utils import parse_qs, urlencode
if version[0] == '3':
@@ -132,6 +133,10 @@ class SetSetting(Setting):
class SearchLanguageSetting(EnumStringSetting):
"""Available choices may change, so user's value may not be in choices anymore"""
+ def _validate_selection(self, selection):
+ if not match_language(selection, self.choices, fallback=None) and selection != "":
+ raise ValidationException('Invalid language code: "{0}"'.format(selection))
+
def parse(self, data):
if data not in self.choices and data != self.value:
# hack to give some backwards compatibility with old language cookies
@@ -268,7 +273,7 @@ class Preferences(object):
super(Preferences, self).__init__()
self.key_value_settings = {'categories': MultipleChoiceSetting(['general'], choices=categories + ['none']),
- 'language': SearchLanguageSetting(settings['ui']['default_locale'],
+ 'language': SearchLanguageSetting(settings['search']['default_lang'],
choices=list(LANGUAGE_CODES) + ['']),
'locale': EnumStringSetting(settings['ui']['default_locale'],
choices=list(settings['locales'].keys()) + ['']),
diff --git a/searx/settings.yml b/searx/settings.yml
index 08ff8dc62..f39a5e32d 100644
--- a/searx/settings.yml
+++ b/searx/settings.yml
@@ -5,6 +5,7 @@ general:
search:
safe_search : 0 # Filter results. 0: None, 1: Moderate, 2: Strict
autocomplete : "" # Existing autocomplete backends: "dbpedia", "duckduckgo", "google", "startpage", "wikipedia" - leave blank to turn it off by default
+ default_lang : "" # Default search language - leave blank to detect from browser information or use codes from 'languages.py'
ban_time_on_fail : 5 # ban time in seconds after engine errors
max_ban_time_on_fail : 120 # max ban time in seconds after engine errors
diff --git a/searx/templates/__common__/about.html b/searx/templates/__common__/about.html
index bf1733359..ff86ddd28 100644
--- a/searx/templates/__common__/about.html
+++ b/searx/templates/__common__/about.html
@@ -22,7 +22,7 @@ Searx can be added to your browser's search bar; moreover, it can be set as the
<h2>How can I make it my own?</h2>
-<p>Searx appreciates your concern regarding logs, so take the <a href="https://github.com/asciimoo/searx">code</a> and run it yourself! <br />Add your Searx to this <a href="https://github.com/asciimoo/searx/wiki/Searx-instances">list</a> to help other people reclaim their privacy and make the Internet freer!
+<p>Searx appreciates your concern regarding logs, so take the <a href="https://github.com/asciimoo/searx">code</a> and run it yourself! <br />Add your Searx to this <a href="https://searx.space/">list</a> to help other people reclaim their privacy and make the Internet freer!
<br />The more decentralized the Internet is, the more freedom we have!</p>
diff --git a/searx/templates/oscar/base.html b/searx/templates/oscar/base.html
index 66a9e6029..9465ca58a 100644
--- a/searx/templates/oscar/base.html
+++ b/searx/templates/oscar/base.html
@@ -88,7 +88,7 @@
{{ _('Powered by') }} <a href="https://asciimoo.github.io/searx/">searx</a> - {{ searx_version }} - {{ _('a privacy-respecting, hackable metasearch engine') }}<br/>
<a href="https://github.com/asciimoo/searx">{{ _('Source code') }}</a> |
<a href="https://github.com/asciimoo/searx/issues">{{ _('Issue tracker') }}</a> |
- <a href="https://github.com/asciimoo/searx/wiki/Searx-instances">{{ _('Public instances') }}</a>
+ <a href="https://searx.space/">{{ _('Public instances') }}</a>
</small>
</p>
</div>
diff --git a/searx/templates/simple/base.html b/searx/templates/simple/base.html
index 92597b654..bba02dbf8 100644
--- a/searx/templates/simple/base.html
+++ b/searx/templates/simple/base.html
@@ -53,7 +53,7 @@
{{ _('Powered by') }} <a href="{{ url_for('about') }}">searx</a> - {{ searx_version }} - {{ _('a privacy-respecting, hackable metasearch engine') }}<br/>
<a href="https://github.com/asciimoo/searx">{{ _('Source code') }}</a> |
<a href="https://github.com/asciimoo/searx/issues">{{ _('Issue tracker') }}</a> |
- <a href="https://github.com/asciimoo/searx/wiki/Searx-instances">{{ _('Public instances') }}</a>
+ <a href="https://searx.space/">{{ _('Public instances') }}</a>
</p>
</footer>
<!--[if gte IE 9]>-->
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 = []