[mod] libretranslate: add direct link to translation (engine)

This commit is contained in:
Thomas Renard 2024-06-29 12:39:31 +02:00 committed by Bnyro
parent adaec68728
commit 39aaac40d6

View File

@ -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