From 39aaac40d63d53555b7fc12d56f0825c85ecf567 Mon Sep 17 00:00:00 2001 From: Thomas Renard Date: Sat, 29 Jun 2024 12:39:31 +0200 Subject: [PATCH] [mod] libretranslate: add direct link to translation (engine) --- searx/engines/libretranslate.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/searx/engines/libretranslate.py b/searx/engines/libretranslate.py index 20fa481f5..a62d88d8a 100644 --- a/searx/engines/libretranslate.py +++ b/searx/engines/libretranslate.py @@ -31,6 +31,7 @@ def request(_query, params): params['method'] = 'POST' params['headers'] = {'Content-Type': 'application/json'} + params['req_url'] = request_url return params @@ -40,7 +41,13 @@ def response(resp): json_resp = resp.json() text = json_resp.get('translatedText') + + from_lang = resp.search_params["from_lang"][1] + to_lang = resp.search_params["to_lang"][1] + query = resp.search_params["query"] + req_url = resp.search_params["req_url"] + if text: - results.append({'answer': text}) + results.append({"answer": text, "url": f"{req_url}/?source={from_lang}&target={to_lang}&q={query}"}) return results