summaryrefslogtreecommitdiff
path: root/searx/webapp.py
diff options
context:
space:
mode:
authorMarkus Heiser <markus.heiser@darmarit.de>2023-01-31 12:40:23 +0100
committerMarkus Heiser <markus.heiser@darmarit.de>2023-04-15 22:23:33 +0200
commitd5ecda99303f1555dc34d824f9dca662bbdda24e (patch)
tree558a23031685ad06864e4458ac4c261a8154e28d /searx/webapp.py
parentc03b0ea650e0a052e422881c6278a5c9a7cca60c (diff)
downloadsearxng-d5ecda99303f1555dc34d824f9dca662bbdda24e.tar.gz
searxng-d5ecda99303f1555dc34d824f9dca662bbdda24e.zip
[mod] move language recognition to get_search_query_from_webapp
To set the language from language recognition and hold the value selected by the client, the previous implementation creates a copy of the SearchQuery object and manipulates the SearchQuery object by calling function replace_auto_language(). This patch tries to implement a similar functionality in a more central place, in function get_search_query_from_webapp() when the SearchQuery object is build up. Additional this patch uses the language preferred by the client, if language recognition does not have a match / the existing implementation does not care about client preferences and uses 'all' in case of no match. Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
Diffstat (limited to 'searx/webapp.py')
-rwxr-xr-xsearx/webapp.py20
1 files changed, 6 insertions, 14 deletions
diff --git a/searx/webapp.py b/searx/webapp.py
index 52b1ccc34..79255652f 100755
--- a/searx/webapp.py
+++ b/searx/webapp.py
@@ -84,6 +84,7 @@ from searx.webutils import (
from searx.webadapter import (
get_search_query_from_webapp,
get_selected_categories,
+ parse_lang,
)
from searx.utils import (
html_to_text,
@@ -440,11 +441,7 @@ def render(template_name: str, **kwargs):
kwargs['rtl'] = True
if 'current_language' not in kwargs:
- _locale = request.preferences.get_value('language')
- if _locale in ('auto', 'all'):
- kwargs['current_language'] = _locale
- else:
- kwargs['current_language'] = match_locale(_locale, settings['search']['languages'])
+ kwargs['current_language'] = parse_lang(request.preferences, {}, RawTextQuery('', []))
# values from settings
kwargs['search_formats'] = [x for x in settings['search']['formats'] if x != 'html']
@@ -678,7 +675,9 @@ def search():
raw_text_query = None
result_container = None
try:
- search_query, raw_text_query, _, _ = get_search_query_from_webapp(request.preferences, request.form)
+ search_query, raw_text_query, _, _, selected_locale = get_search_query_from_webapp(
+ request.preferences, request.form
+ )
# search = Search(search_query) # without plugins
search = SearchWithPlugins(search_query, request.user_plugins, request) # pylint: disable=redefined-outer-name
@@ -809,13 +808,6 @@ def search():
)
)
- if search_query.lang in ('auto', 'all'):
- current_language = search_query.lang
- else:
- current_language = match_locale(
- search_query.lang, settings['search']['languages'], fallback=request.preferences.get_value("language")
- )
-
# search_query.lang contains the user choice (all, auto, en, ...)
# when the user choice is "auto", search.search_query.lang contains the detected language
# otherwise it is equals to search_query.lang
@@ -838,7 +830,7 @@ def search():
result_container.unresponsive_engines
),
current_locale = request.preferences.get_value("locale"),
- current_language = current_language,
+ current_language = selected_locale,
search_language = match_locale(
search.search_query.lang,
settings['search']['languages'],