platypush.plugins.google.translate
¶
-
class
platypush.plugins.google.translate.
GoogleTranslatePlugin
(target_language: str = 'en', credentials_file: Optional[str] = None, **kwargs)[source]¶ Plugin to interact with the Google Translate API. You’ll need a Google Cloud active project and a set of credentials to use this plugin:
- Create a project on the Google Cloud console if you don’t have one already.
- In the menu navigate to the Artificial Intelligence section and select Translations and enable the API.
- From the menu select APIs & Services and create a service account. You can leave role and permissions empty.
- Create a new private JSON key for the service account and download it. By default platypush will look for the
credentials file under
~/.credentials/platypush/google/translate.json
.
Requires:
- google-cloud-translate (
pip install google-cloud-translate
)
-
__init__
(target_language: str = 'en', credentials_file: Optional[str] = None, **kwargs)[source]¶ Parameters: - target_language – Default target language (default: ‘en’).
- credentials_file –
Google service account JSON credentials file. If none is specified then the plugin will search for the credentials file in the following order:
~/.credentials/platypush/google/translate.json
- Context from the
GOOGLE_APPLICATION_CREDENTIALS
environment variable.
-
translate
(text: str, target_language: Optional[str] = None, source_language: Optional[str] = None, format: Optional[str] = None) → platypush.message.response.translate.TranslateResponse[source]¶ Translate a piece of text or HTML.
Parameters: - text – Input text.
- target_language – target_language override.
- source_language – source_language (default: auto-detect).
- format – Input format (available formats:
text
,html
).
Returns: