Plugin Google Translation


For more information, refer to GitHub.


What does this plugin do?

This plugin uses Google Cloud Translation API to translate the user input text and detect its language.

Setup

Install the plugin

To install this plugin, you only need to execute the following command:

npm i @botonic/plugin-google-translation

Enable Cloud Translation API

Before using this plugin, you need a project that has the Cloud Translation API enabled and its credentials. See Cloud Translation Set Up Guide.

Add the plugin

You need to add the following configuration to your bot's plugins:

export const plugins = [
{
id: 'google-translation',
resolve: require('@botonic/plugin-google-translation'),
options: {
credentials: {
privateKeyId: '',
privateKey: '',
projectId: '',
clientEmail: '',
},
translateTo: ['ca', 'it', 'ro'],
whitelist: ['en', 'es'],
},
},
]

Note: Credentials definition is case-sensitive: make sure you correctly define them.

This plugin has two parameters:

  • translateTo: languages we want to translate the input text to.
  • whitelist: optional parameter that defines the allowed languages for language detection. If the detected language is not included in the whitelist, the session.__locale is used.

Important: all languages are specified using its ISO 639-1 code.

Use

Once the plugin has translated the input text and detected the language, this information will be available in the input object.

Was this article useful?