mirror of
https://github.com/searxng/searxng.git
synced 2025-07-14 00:39:18 +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
|
@ -16,12 +16,14 @@
|
|||
from lxml import html
|
||||
from searx.engines.xpath import extract_text
|
||||
from searx.url_utils import urlencode
|
||||
from searx.utils import match_language
|
||||
|
||||
# engine dependent config
|
||||
categories = ['general']
|
||||
paging = True
|
||||
language_support = True
|
||||
supported_languages_url = 'https://www.bing.com/account/general'
|
||||
language_aliases = {'zh-CN': 'zh-CHS', 'zh-TW': 'zh-CHT', 'zh-HK': 'zh-CHT'}
|
||||
|
||||
# search-url
|
||||
base_url = 'https://www.bing.com/'
|
||||
|
@ -32,9 +34,9 @@ search_string = 'search?{query}&first={offset}'
|
|||
def request(query, params):
|
||||
offset = (params['pageno'] - 1) * 10 + 1
|
||||
|
||||
lang = params['language'].split('-')[0].upper()
|
||||
lang = match_language(params['language'], supported_languages, language_aliases)
|
||||
|
||||
query = u'language:{} {}'.format(lang, query.decode('utf-8')).encode('utf-8')
|
||||
query = u'language:{} {}'.format(lang.split('-')[0].upper(), query.decode('utf-8')).encode('utf-8')
|
||||
|
||||
search_path = search_string.format(
|
||||
query=urlencode({'q': query}),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue