[mod] qwant: moved supported_languages to type EngineProperties

"type": "engine_properties"

Supported languages in qwant are locales with a territory tag (aka regions).
Moved `supported_languages` to `EngineProperties.regions`.

Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
This commit is contained in:
Markus Heiser 2022-08-13 17:04:33 +02:00
parent 3b10d63e2f
commit da659123c1
2 changed files with 163 additions and 149 deletions

View file

@ -1397,6 +1397,8 @@
"zh"
],
"qwant": {
"languages": {},
"regions": {
"bg-BG": "bg_BG",
"ca-ES": "ca_ES",
"cs-CZ": "cs_CZ",
@ -1437,7 +1439,11 @@
"zh-CN": "zh_CN",
"zh-HK": "zh_HK"
},
"type": "engine_properties"
},
"qwant images": {
"languages": {},
"regions": {
"bg-BG": "bg_BG",
"ca-ES": "ca_ES",
"cs-CZ": "cs_CZ",
@ -1478,7 +1484,11 @@
"zh-CN": "zh_CN",
"zh-HK": "zh_HK"
},
"type": "engine_properties"
},
"qwant news": {
"languages": {},
"regions": {
"ca-ES": "ca_ES",
"de-AT": "de_AT",
"de-CH": "de_CH",
@ -1504,7 +1514,11 @@
"nl-NL": "nl_NL",
"pt-PT": "pt_PT"
},
"type": "engine_properties"
},
"qwant videos": {
"languages": {},
"regions": {
"bg-BG": "bg_BG",
"ca-ES": "ca_ES",
"cs-CZ": "cs_CZ",
@ -1545,6 +1559,8 @@
"zh-CN": "zh_CN",
"zh-HK": "zh_HK"
},
"type": "engine_properties"
},
"startpage": {
"af": {
"alias": "afrikaans"

View file

@ -49,7 +49,7 @@ about = {
# engine dependent config
categories = []
paging = True
supported_languages_url = about['website']
supported_properties_url = about['website']
qwant_categ = None # web|news|inages|videos
safesearch = True
@ -95,7 +95,7 @@ def request(query, params):
)
# add quant's locale
q_locale = get_engine_locale(params['language'], supported_languages, default='en_US')
q_locale = get_engine_locale(params['language'], supported_properties['regions'], default='en_US')
params['url'] += '&locale=' + q_locale
# add safesearch option
@ -243,7 +243,7 @@ def response(resp):
return results
def _fetch_supported_languages(resp):
def _fetch_engine_properties(resp, engine_properties):
text = resp.text
text = text[text.find('INITIAL_PROPS') :]
@ -263,8 +263,6 @@ def _fetch_supported_languages(resp):
q_valid_locales.append(_locale)
supported_languages = {}
for q_locale in q_valid_locales:
try:
locale = babel.Locale.parse(q_locale, sep='_')
@ -272,7 +270,7 @@ def _fetch_supported_languages(resp):
print("ERROR: can't determine babel locale of quant's locale %s" % q_locale)
continue
# note: supported_languages (dict)
# note: engine_properties.regions (dict)
#
# dict's key is a string build up from a babel.Locale object / the
# notation 'xx-XX' (and 'xx') conforms to SearXNG's locale (and
@ -280,6 +278,6 @@ def _fetch_supported_languages(resp):
# the engine.
searxng_locale = locale.language + '-' + locale.territory # --> params['language']
supported_languages[searxng_locale] = q_locale
engine_properties.regions[searxng_locale] = q_locale
return supported_languages
return engine_properties