This plugin uses Google Cloud Translation API to translate the user input text and detect its language.
To install this plugin, you only need to execute the following command:
npm i @botonic/plugin-google-translation
Before using this plugin, you need a project that has the Cloud Translation API enabled and its credentials. See Cloud Translation Set Up Guide.
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, thesession.__locale
is used.
Important: all languages are specified using its ISO 639-1 code.
Once the plugin has translated the input text and detected the language, this information will be available in the input object.