summaryrefslogtreecommitdiff
path: root/searx/webapp.py
diff options
context:
space:
mode:
authorMarc Abonce Seguin <marc-abonce@mailbox.org>2018-02-28 22:30:48 -0600
committerMarc Abonce Seguin <marc-abonce@mailbox.org>2018-03-27 00:08:03 -0600
commit772c048d01c7585fd60afca1ce30a1914e6e5b4a (patch)
tree96a5662897df2bcf0ab53456e0a67ace998f2169 /searx/webapp.py
parentd1eae9359f8c5920632a730744ea2208070f06da (diff)
downloadsearxng-772c048d01c7585fd60afca1ce30a1914e6e5b4a.tar.gz
searxng-772c048d01c7585fd60afca1ce30a1914e6e5b4a.zip
refactor engine's search language handling
Add match_language function in utils to match any user given language code with a list of engine's supported languages. Also add language_aliases dict on each engine to translate standard language codes into the custom codes used by the engine.
Diffstat (limited to 'searx/webapp.py')
-rw-r--r--searx/webapp.py22
1 files changed, 15 insertions, 7 deletions
diff --git a/searx/webapp.py b/searx/webapp.py
index 2daf60deb..7145caca9 100644
--- a/searx/webapp.py
+++ b/searx/webapp.py
@@ -58,16 +58,16 @@ from searx.engines import (
from searx.utils import (
UnicodeWriter, highlight_content, html_to_text, get_resources_directory,
get_static_files, get_result_templates, get_themes, gen_useragent,
- dict_subset, prettify_url
+ dict_subset, prettify_url, match_language
)
from searx.version import VERSION_STRING
-from searx.languages import language_codes
+from searx.languages import language_codes as languages
from searx.search import SearchWithPlugins, get_search_query_from_webapp
from searx.query import RawTextQuery
from searx.autocomplete import searx_bang, backends as autocomplete_backends
from searx.plugins import plugins
from searx.plugins.oa_doi_rewrite import get_doi_resolver
-from searx.preferences import Preferences, ValidationException
+from searx.preferences import Preferences, ValidationException, LANGUAGE_CODES
from searx.answerers import answerers
from searx.url_utils import urlencode, urlparse, urljoin
from searx.utils import new_hmac
@@ -133,7 +133,7 @@ if not searx_debug \
babel = Babel(app)
rtl_locales = ['ar', 'arc', 'bcc', 'bqi', 'ckb', 'dv', 'fa', 'glk', 'he',
- 'ku', 'mzn', 'pnb'', ''ps', 'sd', 'ug', 'ur', 'yi']
+ 'ku', 'mzn', 'pnb', 'ps', 'sd', 'ug', 'ur', 'yi']
# used when translating category names
_category_names = (gettext('files'),
@@ -352,9 +352,11 @@ def render(template_name, override_theme=None, **kwargs):
kwargs['safesearch'] = str(request.preferences.get_value('safesearch'))
- kwargs['language_codes'] = language_codes
+ kwargs['language_codes'] = languages
if 'current_language' not in kwargs:
- kwargs['current_language'] = request.preferences.get_value('language')
+ kwargs['current_language'] = match_language(request.preferences.get_value('language'),
+ LANGUAGE_CODES,
+ fallback=settings['search']['language'])
# override url_for function in templates
kwargs['url_for'] = url_for_theme
@@ -590,7 +592,9 @@ def index():
infoboxes=result_container.infoboxes,
paging=result_container.paging,
unresponsive_engines=result_container.unresponsive_engines,
- current_language=search_query.lang,
+ current_language=match_language(search_query.lang,
+ LANGUAGE_CODES,
+ fallback=settings['search']['language']),
base_url=get_base_url(),
theme=get_current_theme_name(),
favicons=global_favicons[themes.index(get_current_theme_name())]
@@ -687,6 +691,10 @@ def preferences():
'warn_time': False}
if e.timeout > settings['outgoing']['request_timeout']:
stats[e.name]['warn_timeout'] = True
+ if match_language(request.preferences.get_value('language'),
+ getattr(e, 'supported_languages', []),
+ getattr(e, 'language_aliases', {}), None):
+ stats[e.name]['supports_selected_language'] = True
# get first element [0], the engine time,
# and then the second element [1] : the time (the first one is the label)