.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
searx.engines.libretranslate Namespace Reference

Functions

 request (_query, params)
 
 response (resp)
 

Variables

dict about
 
str engine_type = 'online_dictionary'
 
list categories = ['general', 'translate']
 
str base_url = "https://translate.terraprint.co"
 
str api_key = ''
 

Detailed Description

LibreTranslate (Free and Open Source Machine Translation API)

Function Documentation

◆ request()

searx.engines.libretranslate.request ( _query,
params )

Definition at line 23 of file libretranslate.py.

23def request(_query, params):
24 request_url = random.choice(base_url) if isinstance(base_url, list) else base_url
25 params['url'] = f"{request_url}/translate"
26
27 args = {'source': params['from_lang'][1], 'target': params['to_lang'][1], 'q': params['query']}
28 if api_key:
29 args['api_key'] = api_key
30 params['data'] = dumps(args)
31
32 params['method'] = 'POST'
33 params['headers'] = {'Content-Type': 'application/json'}
34 params['req_url'] = request_url
35
36 return params
37
38

◆ response()

searx.engines.libretranslate.response ( resp)

Definition at line 39 of file libretranslate.py.

39def response(resp):
40 results = []
41
42 json_resp = resp.json()
43 text = json_resp.get('translatedText')
44
45 from_lang = resp.search_params["from_lang"][1]
46 to_lang = resp.search_params["to_lang"][1]
47 query = resp.search_params["query"]
48 req_url = resp.search_params["req_url"]
49
50 if text:
51 results.append({"answer": text, "url": f"{req_url}/?source={from_lang}&target={to_lang}&q={query}"})
52
53 return results

Variable Documentation

◆ about

dict searx.engines.libretranslate.about
Initial value:
1= {
2 "website": 'https://libretranslate.com',
3 "wikidata_id": None,
4 "official_api_documentation": 'https://libretranslate.com/docs/',
5 "use_official_api": True,
6 "require_api_key": False,
7 "results": 'JSON',
8}

Definition at line 7 of file libretranslate.py.

◆ api_key

str searx.engines.libretranslate.api_key = ''

Definition at line 20 of file libretranslate.py.

◆ base_url

str searx.engines.libretranslate.base_url = "https://translate.terraprint.co"

Definition at line 19 of file libretranslate.py.

◆ categories

list searx.engines.libretranslate.categories = ['general', 'translate']

Definition at line 17 of file libretranslate.py.

◆ engine_type

str searx.engines.libretranslate.engine_type = 'online_dictionary'

Definition at line 16 of file libretranslate.py.