summaryrefslogtreecommitdiff
path: root/searx/engines/deepl.py
diff options
context:
space:
mode:
authorBnyro <bnyro@tutanota.com>2024-10-15 15:39:14 +0200
committerMarkus Heiser <markus.heiser@darmarIT.de>2025-01-28 07:07:08 +0100
commit9079d0cac0156139952446f0fdc8b37b94c10756 (patch)
tree0164ae5b30d173cda9e60ea8048b16033b2029cc /searx/engines/deepl.py
parent70f1b6500861970f8b9e52fbfe52a1796350ea69 (diff)
[refactor] translation engines: common interface
Diffstat (limited to 'searx/engines/deepl.py')
-rw-r--r--searx/engines/deepl.py14
1 files changed, 5 insertions, 9 deletions
diff --git a/searx/engines/deepl.py b/searx/engines/deepl.py
index ce2109138..484f56ec4 100644
--- a/searx/engines/deepl.py
+++ b/searx/engines/deepl.py
@@ -1,8 +1,6 @@
# SPDX-License-Identifier: AGPL-3.0-or-later
"""Deepl translation engine"""
-from json import loads
-
about = {
"website": 'https://deepl.com',
"wikidata_id": 'Q43968444',
@@ -41,16 +39,14 @@ def request(_query, params):
def response(resp):
results = []
- result = loads(resp.text)
- translations = result['translations']
- infobox = "<dl>"
+ result = resp.json()
- for translation in translations:
- infobox += f"<dd>{translation['text']}</dd>"
+ if not result.get('translations'):
+ return results
- infobox += "</dl>"
+ translations = [{'text': translation['text']} for translation in result['translations']]
- results.append({'answer': infobox})
+ results.append({'answer': translations[0]['text'], 'answer_type': 'translations', 'translations': translations})
return results