forked from platypush/platypush
[#398] Removed TranslateResponse
.
This commit is contained in:
parent
825f20ab77
commit
6003b205c8
4 changed files with 16 additions and 32 deletions
|
@ -1,5 +0,0 @@
|
||||||
``translate``
|
|
||||||
========================================
|
|
||||||
|
|
||||||
.. automodule:: platypush.message.response.translate
|
|
||||||
:members:
|
|
|
@ -9,4 +9,3 @@ Responses
|
||||||
platypush/responses/google.drive.rst
|
platypush/responses/google.drive.rst
|
||||||
platypush/responses/printer.cups.rst
|
platypush/responses/printer.cups.rst
|
||||||
platypush/responses/tensorflow.rst
|
platypush/responses/tensorflow.rst
|
||||||
platypush/responses/translate.rst
|
|
||||||
|
|
|
@ -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:
|
|
|
@ -3,7 +3,6 @@ from typing import Optional, List
|
||||||
|
|
||||||
from google.cloud import translate_v2 as translate
|
from google.cloud import translate_v2 as translate
|
||||||
|
|
||||||
from platypush.message.response.translate import TranslateResponse
|
|
||||||
from platypush.plugins import action, Plugin
|
from platypush.plugins import action, Plugin
|
||||||
|
|
||||||
|
|
||||||
|
@ -98,7 +97,7 @@ class GoogleTranslatePlugin(Plugin):
|
||||||
target_language: Optional[str] = None,
|
target_language: Optional[str] = None,
|
||||||
source_language: Optional[str] = None,
|
source_language: Optional[str] = None,
|
||||||
format: Optional[str] = None,
|
format: Optional[str] = None,
|
||||||
) -> TranslateResponse:
|
) -> dict:
|
||||||
"""
|
"""
|
||||||
Translate a piece of text or HTML.
|
Translate a piece of text or HTML.
|
||||||
|
|
||||||
|
@ -106,7 +105,16 @@ class GoogleTranslatePlugin(Plugin):
|
||||||
:param target_language: target_language override.
|
:param target_language: target_language override.
|
||||||
:param source_language: source_language (default: auto-detect).
|
:param source_language: source_language (default: auto-detect).
|
||||||
:param format: Input format (available formats: ``text``, ``html``).
|
: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
|
target_language = target_language or self.target_language
|
||||||
args = {}
|
args = {}
|
||||||
|
@ -127,11 +135,11 @@ class GoogleTranslatePlugin(Plugin):
|
||||||
else:
|
else:
|
||||||
result['translatedText'] += ' ' + response['translatedText']
|
result['translatedText'] += ' ' + response['translatedText']
|
||||||
|
|
||||||
return TranslateResponse(
|
return {
|
||||||
translated_text=result.get('translatedText'),
|
'translated_text': result.get('translatedText'),
|
||||||
source_text=text,
|
'source_text': text,
|
||||||
detected_source_language=result.get('detectedSourceLanguage'),
|
'detected_source_language': result.get('detectedSourceLanguage'),
|
||||||
)
|
}
|
||||||
|
|
||||||
|
|
||||||
# vim:sw=4:ts=4:et:
|
# vim:sw=4:ts=4:et:
|
||||||
|
|
Loading…
Reference in a new issue