.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
deepl.py
Go to the documentation of this file.
1# SPDX-License-Identifier: AGPL-3.0-or-later
2"""Deepl translation engine"""
3
4from json import loads
5
6about = {
7 "website": 'https://deepl.com',
8 "wikidata_id": 'Q43968444',
9 "official_api_documentation": 'https://www.deepl.com/docs-api',
10 "use_official_api": True,
11 "require_api_key": True,
12 "results": 'JSON',
13}
14
15engine_type = 'online_dictionary'
16categories = ['general', 'translate']
17
18url = 'https://api-free.deepl.com/v2/translate'
19api_key = None
20
21
22def request(_query, params):
23 '''pre-request callback
24
25 params<dict>:
26
27 - ``method`` : POST/GET
28 - ``headers``: {}
29 - ``data``: {} # if method == POST
30 - ``url``: ''
31 - ``category``: 'search category'
32 - ``pageno``: 1 # number of the requested page
33 '''
34
35 params['url'] = url
36 params['method'] = 'POST'
37 params['data'] = {'auth_key': api_key, 'text': params['query'], 'target_lang': params['to_lang'][1]}
38
39 return params
40
41
42def response(resp):
43 results = []
44 result = loads(resp.text)
45 translations = result['translations']
46
47 infobox = "<dl>"
48
49 for translation in translations:
50 infobox += f"<dd>{translation['text']}</dd>"
51
52 infobox += "</dl>"
53
54 results.append({'answer': infobox})
55
56 return results
request(_query, params)
Definition deepl.py:22