mirror of
https://github.com/searxng/searxng.git
synced 2025-08-01 01:22:22 +02:00
[fix] multilingual duckduckgo
only works if both country and language are set
This commit is contained in:
parent
3fd405dcd3
commit
8fc4b8156a
2 changed files with 16 additions and 13 deletions
|
@ -11,8 +11,6 @@
|
|||
@parse url, title, content
|
||||
|
||||
@todo rewrite to api
|
||||
@todo language support
|
||||
(the current used site does not support language-change)
|
||||
"""
|
||||
|
||||
from urllib import urlencode
|
||||
|
@ -39,13 +37,22 @@ def request(query, params):
|
|||
offset = (params['pageno'] - 1) * 30
|
||||
|
||||
if params['language'] == 'all':
|
||||
locale = 'en-us'
|
||||
locale = None
|
||||
else:
|
||||
locale = params['language'].replace('_', '-').lower()
|
||||
locale = params['language'].split('_')
|
||||
if len(locale) == 2:
|
||||
# country code goes first
|
||||
locale = locale[1].lower() + '-' + locale[0].lower()
|
||||
else:
|
||||
# doesn't actually do anything because ddg requires both country and language
|
||||
locale = locale[0].lower()
|
||||
|
||||
params['url'] = url.format(
|
||||
query=urlencode({'q': query, 'kl': locale}),
|
||||
offset=offset)
|
||||
if locale:
|
||||
params['url'] = url.format(
|
||||
query=urlencode({'q': query, 'kl': locale}), offset=offset)
|
||||
else:
|
||||
params['url'] = url.format(
|
||||
query=urlencode({'q': query}), offset=offset)
|
||||
|
||||
return params
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue