Unverified Commit 98322ac1 authored by Markus Heiser's avatar Markus Heiser Committed by GitHub

Merge branch 'master' into engine-etools

parents e1b60106 90d23e7e
...@@ -7,7 +7,7 @@ engine <https://en.wikipedia.org/wiki/Metasearch_engine>`__. ...@@ -7,7 +7,7 @@ engine <https://en.wikipedia.org/wiki/Metasearch_engine>`__.
Pronunciation: səːks Pronunciation: səːks
List of `running List of `running
instances <https://github.com/asciimoo/searx/wiki/Searx-instances>`__. instances <https://searx.space/>`__.
See the `documentation <https://asciimoo.github.io/searx>`__ and the `wiki <https://github.com/asciimoo/searx/wiki>`__ for more information. See the `documentation <https://asciimoo.github.io/searx>`__ and the `wiki <https://github.com/asciimoo/searx/wiki>`__ for more information.
......
...@@ -11,7 +11,7 @@ DOCS_URL = os.environ.get("DOCS_URL", "https://asciimoo.github.io/searx/") ...@@ -11,7 +11,7 @@ DOCS_URL = os.environ.get("DOCS_URL", "https://asciimoo.github.io/searx/")
# Project -------------------------------------------------------------- # Project --------------------------------------------------------------
project = u'searx' project = u'searx'
copyright = u'2015-2019, Adam Tauber, Noémi Ványi' copyright = u'2015-2020, Adam Tauber, Noémi Ványi'
author = u'Adam Tauber' author = u'Adam Tauber'
release, version = VERSION_STRING, VERSION_STRING release, version = VERSION_STRING, VERSION_STRING
highlight_language = 'none' highlight_language = 'none'
...@@ -94,7 +94,7 @@ html_context = { ...@@ -94,7 +94,7 @@ html_context = {
"project_links": [ "project_links": [
ProjectLink("Source", GIT_URL), ProjectLink("Source", GIT_URL),
ProjectLink("Wiki", "https://github.com/asciimoo/searx/wiki"), ProjectLink("Wiki", "https://github.com/asciimoo/searx/wiki"),
ProjectLink("Public instances", "https://asciimoo.github.io/searx/user/public_instances.html"), ProjectLink("Public instances", "https://searx.space/"),
ProjectLink("Twitter", "https://twitter.com/Searx_engine"), ProjectLink("Twitter", "https://twitter.com/Searx_engine"),
] ]
} }
......
...@@ -285,7 +285,7 @@ content becomes smart. ...@@ -285,7 +285,7 @@ content becomes smart.
:rst:role:`pep` :pep:`8` ``:pep:`8``` :rst:role:`pep` :pep:`8` ``:pep:`8```
sphinx.ext.extlinks_ sphinx.ext.extlinks_
-------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------
project's wiki article :wiki:`Searx-instances` ``:wiki:`Searx-instances``` project's wiki article :wiki:`Offline-engines` ``:wiki:`Offline-engines```
to docs public URL :docs:`dev/reST.html` ``:docs:`dev/reST.html``` to docs public URL :docs:`dev/reST.html` ``:docs:`dev/reST.html```
files & folders origin :origin:`docs/dev/reST.rst` ``:origin:`docs/dev/reST.rst``` files & folders origin :origin:`docs/dev/reST.rst` ``:origin:`docs/dev/reST.rst```
pull request :pull:`1756` ``:pull:`1756``` pull request :pull:`1756` ``:pull:`1756```
......
...@@ -20,8 +20,8 @@ Searx is a free internet metasearch engine which aggregates results from more ...@@ -20,8 +20,8 @@ Searx is a free internet metasearch engine which aggregates results from more
than 70 search services. Users are neither tracked nor profiled. Additionally, than 70 search services. Users are neither tracked nor profiled. Additionally,
searx can be used over Tor for online anonymity. searx can be used over Tor for online anonymity.
Get started with searx by using one of the :wiki:`Searx-instances`. If you Get started with searx by using one of the Searx-instances_. If you don't trust
don't trust anyone, you can set up your own, see :ref:`installation`. anyone, you can set up your own, see :ref:`installation`.
.. toctree:: .. toctree::
:maxdepth: 2 :maxdepth: 2
...@@ -30,3 +30,5 @@ don't trust anyone, you can set up your own, see :ref:`installation`. ...@@ -30,3 +30,5 @@ don't trust anyone, you can set up your own, see :ref:`installation`.
admin/index admin/index
dev/index dev/index
blog/index blog/index
.. _Searx-instances: https://searx.space
...@@ -5,6 +5,5 @@ User documentation ...@@ -5,6 +5,5 @@ User documentation
.. toctree:: .. toctree::
:maxdepth: 1 :maxdepth: 1
public_instances
search_syntax search_syntax
own-instance own-instance
This diff is collapsed.
...@@ -4,6 +4,7 @@ from sys import version ...@@ -4,6 +4,7 @@ from sys import version
from searx import settings, autocomplete from searx import settings, autocomplete
from searx.languages import language_codes as languages from searx.languages import language_codes as languages
from searx.utils import match_language
from searx.url_utils import parse_qs, urlencode from searx.url_utils import parse_qs, urlencode
if version[0] == '3': if version[0] == '3':
...@@ -132,6 +133,10 @@ class SetSetting(Setting): ...@@ -132,6 +133,10 @@ class SetSetting(Setting):
class SearchLanguageSetting(EnumStringSetting): class SearchLanguageSetting(EnumStringSetting):
"""Available choices may change, so user's value may not be in choices anymore""" """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): def parse(self, data):
if data not in self.choices and data != self.value: if data not in self.choices and data != self.value:
# hack to give some backwards compatibility with old language cookies # hack to give some backwards compatibility with old language cookies
...@@ -268,7 +273,7 @@ class Preferences(object): ...@@ -268,7 +273,7 @@ class Preferences(object):
super(Preferences, self).__init__() super(Preferences, self).__init__()
self.key_value_settings = {'categories': MultipleChoiceSetting(['general'], choices=categories + ['none']), 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) + ['']), choices=list(LANGUAGE_CODES) + ['']),
'locale': EnumStringSetting(settings['ui']['default_locale'], 'locale': EnumStringSetting(settings['ui']['default_locale'],
choices=list(settings['locales'].keys()) + ['']), choices=list(settings['locales'].keys()) + ['']),
......
...@@ -5,6 +5,7 @@ general: ...@@ -5,6 +5,7 @@ general:
search: search:
safe_search : 0 # Filter results. 0: None, 1: Moderate, 2: Strict 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 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 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 max_ban_time_on_fail : 120 # max ban time in seconds after engine errors
......
...@@ -22,7 +22,7 @@ Searx can be added to your browser's search bar; moreover, it can be set as the ...@@ -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> <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> <br />The more decentralized the Internet is, the more freedom we have!</p>
......
...@@ -88,7 +88,7 @@ ...@@ -88,7 +88,7 @@
{{ _('Powered by') }} <a href="https://asciimoo.github.io/searx/">searx</a> - {{ searx_version }} - {{ _('a privacy-respecting, hackable metasearch engine') }}<br/> {{ _('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">{{ _('Source code') }}</a> |
<a href="https://github.com/asciimoo/searx/issues">{{ _('Issue tracker') }}</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> </small>
</p> </p>
</div> </div>
......
...@@ -53,7 +53,7 @@ ...@@ -53,7 +53,7 @@
{{ _('Powered by') }} <a href="{{ url_for('about') }}">searx</a> - {{ searx_version }} - {{ _('a privacy-respecting, hackable metasearch engine') }}<br/> {{ _('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">{{ _('Source code') }}</a> |
<a href="https://github.com/asciimoo/searx/issues">{{ _('Issue tracker') }}</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> </p>
</footer> </footer>
<!--[if gte IE 9]>--> <!--[if gte IE 9]>-->
......
...@@ -157,14 +157,16 @@ _category_names = (gettext('files'), ...@@ -157,14 +157,16 @@ _category_names = (gettext('files'),
outgoing_proxies = settings['outgoing'].get('proxies') or None 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 @babel.localeselector
def get_locale(): def get_locale():
locale = "en-US" locale = _get_browser_language(request, settings['locales'].keys())
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
logger.debug("default locale from browser info is `%s`", locale) logger.debug("default locale from browser info is `%s`", locale)
...@@ -372,8 +374,7 @@ def render(template_name, override_theme=None, **kwargs): ...@@ -372,8 +374,7 @@ def render(template_name, override_theme=None, **kwargs):
kwargs['language_codes'] = languages kwargs['language_codes'] = languages
if 'current_language' not in kwargs: if 'current_language' not in kwargs:
kwargs['current_language'] = match_language(request.preferences.get_value('language'), kwargs['current_language'] = match_language(request.preferences.get_value('language'),
LANGUAGE_CODES, LANGUAGE_CODES)
fallback=locale)
# override url_for function in templates # override url_for function in templates
kwargs['url_for'] = url_for_theme kwargs['url_for'] = url_for_theme
...@@ -444,11 +445,10 @@ def pre_request(): ...@@ -444,11 +445,10 @@ def pre_request():
request.errors.append(gettext('Invalid settings')) request.errors.append(gettext('Invalid settings'))
# init search language and locale # init search language and locale
locale = get_locale()
if not preferences.get_value("language"): 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"): if not preferences.get_value("locale"):
preferences.parse_dict({"locale": locale}) preferences.parse_dict({"locale": get_locale()})
# request.user_plugins # request.user_plugins
request.user_plugins = [] request.user_plugins = []
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment