|
@@ -11,13 +11,12 @@
|
11
|
11
|
@parse url, title, content
|
12
|
12
|
|
13
|
13
|
@todo rewrite to api
|
14
|
|
- @todo language support
|
15
|
|
- (the current used site does not support language-change)
|
16
|
14
|
"""
|
17
|
15
|
|
18
|
16
|
from urllib import urlencode
|
19
|
17
|
from lxml.html import fromstring
|
20
|
18
|
from searx.engines.xpath import extract_text
|
|
19
|
+from searx.languages import language_codes
|
21
|
20
|
|
22
|
21
|
# engine dependent config
|
23
|
22
|
categories = ['general']
|
|
@@ -39,13 +38,28 @@ def request(query, params):
|
39
|
38
|
offset = (params['pageno'] - 1) * 30
|
40
|
39
|
|
41
|
40
|
if params['language'] == 'all':
|
42
|
|
- locale = 'en-us'
|
|
41
|
+ locale = None
|
43
|
42
|
else:
|
44
|
|
- locale = params['language'].replace('_', '-').lower()
|
45
|
|
-
|
46
|
|
- params['url'] = url.format(
|
47
|
|
- query=urlencode({'q': query, 'kl': locale}),
|
48
|
|
- offset=offset)
|
|
43
|
+ locale = params['language'].split('_')
|
|
44
|
+ if len(locale) == 2:
|
|
45
|
+ # country code goes first
|
|
46
|
+ locale = locale[1].lower() + '-' + locale[0].lower()
|
|
47
|
+ else:
|
|
48
|
+ # tries to get a country code from language
|
|
49
|
+ locale = locale[0].lower()
|
|
50
|
+ lang_codes = [x[0] for x in language_codes]
|
|
51
|
+ for lc in lang_codes:
|
|
52
|
+ lc = lc.split('_')
|
|
53
|
+ if locale == lc[0]:
|
|
54
|
+ locale = lc[1].lower() + '-' + lc[0].lower()
|
|
55
|
+ break
|
|
56
|
+
|
|
57
|
+ if locale:
|
|
58
|
+ params['url'] = url.format(
|
|
59
|
+ query=urlencode({'q': query, 'kl': locale}), offset=offset)
|
|
60
|
+ else:
|
|
61
|
+ params['url'] = url.format(
|
|
62
|
+ query=urlencode({'q': query}), offset=offset)
|
49
|
63
|
|
50
|
64
|
return params
|
51
|
65
|
|