summaryrefslogtreecommitdiff
path: root/searx/engines/qwant.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/engines/qwant.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/engines/qwant.py')
-rw-r--r--searx/engines/qwant.py13
1 files changed, 3 insertions, 10 deletions
diff --git a/searx/engines/qwant.py b/searx/engines/qwant.py
index 408c2b3de..239193b96 100644
--- a/searx/engines/qwant.py
+++ b/searx/engines/qwant.py
@@ -14,6 +14,7 @@ from datetime import datetime
from json import loads
from searx.utils import html_to_text
from searx.url_utils import urlencode
+from searx.utils import match_language
# engine dependent config
categories = None
@@ -45,16 +46,8 @@ def request(query, params):
offset=offset)
# add language tag
- if params['language'] == 'no' or params['language'].startswith('no-'):
- params['language'] = params['language'].replace('no', 'nb', 1)
- if params['language'].find('-') < 0:
- # tries to get a country code from language
- for lang in supported_languages:
- lc = lang.split('-')
- if params['language'] == lc[0]:
- params['language'] = lang
- break
- params['url'] += '&locale=' + params['language'].replace('-', '_').lower()
+ language = match_language(params['language'], supported_languages)
+ params['url'] += '&locale=' + language.replace('-', '_').lower()
return params