[#398] Removed TranslateResponse.

This commit is contained in:
Fabio Manganiello 2024-05-13 00:45:03 +02:00
parent 825f20ab77
commit 6003b205c8
Signed by: blacklight
GPG key ID: D90FBA7F76362774
4 changed files with 16 additions and 32 deletions

View file

@ -1,5 +0,0 @@
``translate``
========================================
.. automodule:: platypush.message.response.translate
:members:

View file

@ -9,4 +9,3 @@ Responses
platypush/responses/google.drive.rst
platypush/responses/printer.cups.rst
platypush/responses/tensorflow.rst
platypush/responses/translate.rst

View file

@ -1,18 +0,0 @@
from platypush.message.response import Response
class TranslateResponse(Response):
def __init__(self,
translated_text: str,
source_text: str,
detected_source_language: str,
*args,
**kwargs):
super().__init__(*args, output={
'translated_text': translated_text,
'source_text': source_text,
'detected_source_language': detected_source_language,
}, **kwargs)
# vim:sw=4:ts=4:et:

View file

@ -3,7 +3,6 @@ from typing import Optional, List
from google.cloud import translate_v2 as translate
from platypush.message.response.translate import TranslateResponse
from platypush.plugins import action, Plugin
@ -98,7 +97,7 @@ class GoogleTranslatePlugin(Plugin):
target_language: Optional[str] = None,
source_language: Optional[str] = None,
format: Optional[str] = None,
) -> TranslateResponse:
) -> dict:
"""
Translate a piece of text or HTML.
@ -106,7 +105,16 @@ class GoogleTranslatePlugin(Plugin):
:param target_language: target_language override.
:param source_language: source_language (default: auto-detect).
:param format: Input format (available formats: ``text``, ``html``).
:return: :class:`platypush.message.response.translate.TranslateResponse`.
:return: dict
.. code-block:: json
{
"translated_text": "Translated text",
"source_text": "Source text",
"detected_source_language": "Detected source language"
}
"""
target_language = target_language or self.target_language
args = {}
@ -127,11 +135,11 @@ class GoogleTranslatePlugin(Plugin):
else:
result['translatedText'] += ' ' + response['translatedText']
return TranslateResponse(
translated_text=result.get('translatedText'),
source_text=text,
detected_source_language=result.get('detectedSourceLanguage'),
)
return {
'translated_text': result.get('translatedText'),
'source_text': text,
'detected_source_language': result.get('detectedSourceLanguage'),
}
# vim:sw=4:ts=4:et: