Real-Time Translations
How to use real-time language detection and translations
In this article we'll discuss the functionality around real-time language detection and translations. You'll find out what the feature does, and how you can benefit from this powerful feature with minimal effort.
Introduction
Conversational AI Cloud content is built in language-specific environments. The platform allows you to define multiple languages, so that each language can benefit from its own conversational flows depending on what customer service you want to offer in different regions, and cultures.
However, you will have customers interacting with your content in languages that are different from the content you've created. In order to still answer these customers correctly, in their language of choice you can choose to enable real-time language detection and translations.
Enabling real-time language detection and translations
To enable this feature go to the Conversational AI Cloud admin environment. Navigate to the projects tab, select your project, and toggle the feature on per project under the settings tab. After enabling the feature, Conversational AI Cloud will automatically start detecting the input language, and translate any questions and answers!
The first time Conversational AI Cloud detects a language different from the specified culture it will set the language for that session to the detected language. Once set, we will no longer perform language detection on incoming interactions, and instead translate all interactions to the detected language. This is done to avoid unintended swapping between sessions for each interaction. Find out more about how you can easily override the detected language in the rest of this article.
Translate Input and Output
If you know the language a specific interaction needs to be processed in (skipping language detection) you can provide it through the inputLanguage query parameter. Providing this parameter will:
- Translate the provided input to the culture sent in through the culture parameter from the provided language.
- Translate the output from the Gateway API to the provided language.
- Overrides (if set) the language set for this session (either through this parameter, or through automatic language detection)
An example request could be:
const axios = require("axios").default;
const options = {
method: 'GET',
url: 'https://api.digitalcx.com/ask',
params: {
customerKey: 'your-customer-key',
projectKey: 'your-project-key',
culture: 'your-projects-culture',
apiKey: 'your-api-key',
q: 'hola, cómo estás',
inputLanguage: 'es'
}
headers: {
Accept: 'application/json, standard'
}
};
axios.request(options).then(function (response) {
console.log(response.data);
}).catch(function (error) {
console.error(error);
});
This will return the following response from the Gateway API:
{
"outputs": [{
"outputId": 0,
"kbaId": 0,
"interactionValue": "Hi, how are you",
"isDefault": true,
"dimensionValues": [],
"outputParts": [{
"type": "answer",
"text": "¡Hola! ¿Algo en lo que pueda ayudarte?",
"links": [],
"projectConstants": [],
"dialogOptions": [],
"metadata": {},
"images": [],
"videos": []
}],
"kbaCategories": []
}],
"sessionId": "00000000-0000-0000-000000000000",
"interactionId": "00000000-0000-0000-000000000000",
"culture": "en",
"inputs": {
"originalInputText": "hola, cómo estás",
"translatedInputText": "Hi, how are you",
"inputLanguage": "es",
"originalOutput": [{
"outputId": 0,
"kbaId": 0,
"interactionValue": "Hi, how are you",
"isDefault": true,
"dimensionValues": [],
"outputParts": [{
"type": "answer",
"text": "Hi there! Anything I can help you with?",
"links": [],
"projectConstants": [],
"dialogOptions": [],
"metadata": {},
"images": [],
"videos": []
}],
"kbaCategories": []
}]
}
}
If we look at the response then there are a few properties we should be aware of:
- The interaction value (English) in the outputs arrays is different from the originalInputText (Spanish)
- The answer text is in Spanish, even though the projects content is English
- The inputs objects originalInputText contains the original Spanish question we provided
- The inputs objects translatedInputText contains the result of our translation engine, which is Spanish (based on the inputLanguage we sent in)
- The inputs objects inputLanguage value is set to the inputLanguage we specified in the query parameter
- The inputs objects originalOutput value contains the non-translated (English in this example) output
Original Content
If a translation took place for an interaction, Conversational AI Cloud makes sure you still receive the original (untranslated) output. This enables UI features such as language toggles (original/translated), language change confirmation prompts (in case of language detection), and more use-cases to improve and control your end-users' UX.
Disabling Language Detection
If you want to disable language detection, or translations for a specific interaction you can do so by providing the disableTranslations query parameter and setting it to false.
This parameter does not clear the language of the session. To change the language of the session you can provide the inputLanguage query parameter as described. To avoid any automatic language detection, or translations for a session you should specify the inputLanguage query parameter at least once for any session.
An example request that disables language detection and translations looks like this:
const axios = require("axios").default;
const options = {
method: 'GET',
url: 'https://api.digitalcx.com/ask',
params: {
customerKey: 'your-customer-key',
projectKey: 'your-project-key',
culture: 'your-projects-culture',
apiKey: 'your-api-key',
q: 'Hi, how are you',
disableTranslations: true
}
headers: {
Accept: 'application/json, standard'
}
};
axios.request(options).then(function (response) {
console.log(response.data);
}).catch(function (error) {
console.error(error);
});
The response is a standard Gateway response:
{
"outputs": [{
"outputId": 0,
"kbaId": 0,
"interactionValue": "Hi, how are you",
"isDefault": true,
"dimensionValues": [],
"outputParts": [{
"type": "answer",
"text": "Hi there! Anything I can help you with?",
"links": [],
"projectConstants": [],
"dialogOptions": [],
"metadata": {},
"images": [],
"videos": []
}],
"kbaCategories": []
}],
"sessionId": "00000000-0000-0000-000000000000",
"interactionId": "00000000-0000-0000-000000000000",
"culture": "en",
"inputs": {
"originalInputText": "Hi, how are you"
}
}
Next Steps
Now that you've had the change to take a brief look at Conversational AI Cloud's real-time language detection and translations feature you're able to easily provide your content in over a hundred languages with no effort whatsoever!
Make sure to take a look at our Language Support article to find out what languages this feature supports, and how!
Updated 12 months ago