platypush/plugins/google/translate/__init__.py
def translate(self, text: str, target_language: Optional[str] = None, source_language: Optional[str] = None,
                  format: Optional[str] = None) -> TranslateResponse:
        """
        Translate a piece of text or HTML.

        :param text: Input text.
        :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`.
        """
        target_language = target_language or self.target_language
        args = {}
        if target_language:
            args['target_language'] = target_language

        client = translate.Client(**args)
        if source_language:
            args['source_language'] = source_language

        inputs = self._split_text(text)
        result = {}

        for input in inputs:
            response = client.translate(input, format_=format, **args)
            if not result:
                result = response
            else:
                # noinspection PyTypeChecker
                result['translatedText'] += ' ' + response['translatedText']

        return TranslateResponse(
            translated_text=result.get('translatedText'),
            source_text=text,
            detected_source_language=result.get('detectedSourceLanguage'),
        )

        Translate a piece of text or HTML.

        :param text: Input text.
        :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`.
        
Translate a piece of text or HTML.
Translate a piece of text or HTML .
def translate(self, text: str, target_language: Optional[str] = None, source_language: Optional[str] = None,
                  format: Optional[str] = None) -> TranslateResponse:
        target_language = target_language or self.target_language
        args = {}
        if target_language:
            args['target_language'] = target_language
        client = translate.Client(**args)
        if source_language:
            args['source_language'] = source_language
        inputs = self._split_text(text)
        result = {}
        for input in inputs:
            response = client.translate(input, format_=format, **args)
            if not result:
                result = response
            else:
                result['translatedText'] += ' ' + response['translatedText']
        return TranslateResponse(
            translated_text=result.get('translatedText'),
            source_text=text,
            detected_source_language=result.get('detectedSourceLanguage'),
        )
def translate ( self , text : str , target_language : Optional [ str ] = None , source_language : Optional [ str ] = None , format : Optional [ str ] = None ) -> TranslateResponse : target_language = target_language or self . target_language args = { } if target_language : args [ 'target_language' ] = target_language client = translate . Client ( ** args ) if source_language : args [ 'source_language' ] = source_language inputs = self . _split_text ( text ) result = { } for input in inputs : response = client . translate ( input , format_ = format , ** args ) if not result : result = response else : result [ 'translatedText' ] += ' ' + response [ 'translatedText' ] return TranslateResponse ( translated_text = result . get ( 'translatedText' ) , source_text = text , detected_source_language = result . get ( 'detectedSourceLanguage' ) , )
Translate a piece of text or HTML.
Translate a piece of text or HTML .
"""
        Translate a piece of text or HTML.

        :param text: Input text.
        :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`.
        """ # noinspection PyTypeChecker
None
self
text
str
None
target_language
Optional[str]
None
source_language
Optional[str]
source_language (default: auto-detect).
source_language ( default : auto - detect ) .
format
Optional[str]
Input format (available formats: ``text``, ``html``).
Input format ( available formats : ` ` text ` ` ` ` html ` ` ) .