diff options
| author | Bnyro <bnyro@tutanota.com> | 2024-10-15 15:39:14 +0200 |
|---|---|---|
| committer | Markus Heiser <markus.heiser@darmarIT.de> | 2025-01-28 07:07:08 +0100 |
| commit | 9079d0cac0156139952446f0fdc8b37b94c10756 (patch) | |
| tree | 0164ae5b30d173cda9e60ea8048b16033b2029cc /searx/engines/translated.py | |
| parent | 70f1b6500861970f8b9e52fbfe52a1796350ea69 (diff) | |
[refactor] translation engines: common interface
Diffstat (limited to 'searx/engines/translated.py')
| -rw-r--r-- | searx/engines/translated.py | 28 |
1 files changed, 13 insertions, 15 deletions
diff --git a/searx/engines/translated.py b/searx/engines/translated.py index ea8c081dc..190707a95 100644 --- a/searx/engines/translated.py +++ b/searx/engines/translated.py @@ -35,18 +35,16 @@ def request(query, params): # pylint: disable=unused-argument def response(resp): - results = [] - results.append( - { - 'url': web_url.format( - from_lang=resp.search_params['from_lang'][2], - to_lang=resp.search_params['to_lang'][2], - query=resp.search_params['query'], - ), - 'title': '[{0}-{1}] {2}'.format( - resp.search_params['from_lang'][1], resp.search_params['to_lang'][1], resp.search_params['query'] - ), - 'content': resp.json()['responseData']['translatedText'], - } - ) - return results + json_resp = resp.json() + text = json_resp['responseData']['translatedText'] + + alternatives = [match['translation'] for match in json_resp['matches'] if match['translation'] != text] + translations = [{'text': translation} for translation in [text] + alternatives] + + result = { + 'answer': translations[0]['text'], + 'answer_type': 'translations', + 'translations': translations, + } + + return [result] |