mirror of
https://github.com/searxng/searxng.git
synced 2025-07-19 03:09:25 +02:00
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.
This commit is contained in:
parent
d1eae9359f
commit
772c048d01
42 changed files with 275 additions and 171 deletions
|
@ -13,6 +13,7 @@
|
|||
from json import loads
|
||||
from lxml.html import fromstring
|
||||
from searx.url_utils import quote, urlencode
|
||||
from searx.utils import match_language
|
||||
|
||||
# search-url
|
||||
base_url = u'https://{language}.wikipedia.org/'
|
||||
|
@ -30,13 +31,7 @@ supported_languages_url = 'https://meta.wikimedia.org/wiki/List_of_Wikipedias'
|
|||
|
||||
# set language in base_url
|
||||
def url_lang(lang):
|
||||
lang = lang.split('-')[0]
|
||||
if lang not in supported_languages:
|
||||
language = 'en'
|
||||
else:
|
||||
language = lang
|
||||
|
||||
return language
|
||||
return match_language(lang, supported_languages).split('-')[0]
|
||||
|
||||
|
||||
# do search-request
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue