Translate

As seen in the Say and Listen section, the Relay device supports multiple languages. In this section, we will go over how to use the Relay device to translate between languages in a workflow.

📘

URN type for Translate

Translate is one of the few APIs that does not require a target URN. So no device URN or interaction URN needs to be specified. This is because the translation function by itself is text-to-text which runs on the Relay server and does not manifest itself directly on a device. You can use the output of translate in another device manifestation like say.

Using the translate function

The translation API in Relay receives a text string in one language and can translate it to a text string in another language. This can be combined with other actions, such as using listen to get the input string, and say to verbalize the output string. The Relay device has the Translate channel that can be enabled via Dash to use that built-in workflow. But with this API you can choose to use it in a different combination.

The translate method takes in three parameters: the phrase you would like to be translated, the phrase's existing language (the language you would like to translate from), and the language you would like to translate to. It will return a string of the phrase in the translate-to language.

Here is an example of a simple workflow that uses the translate() method to translate from English to Spanish:

...
const phrase = "Where is the bathroom?"

// Return the phrase as a string in the desired langage.  In this case, English to Spanish.
const { text: translation } = await workflow.translate(phrase, 'en-US', 'es-ES'))
// translation result is "¿Dónde está el baño?"
...
phrase = "Where is the bathroom?"

# Return the phrase as a string in the desired langage.  In this case, English to Spanish.
translation = await workflow.translate(phrase, 'en-US', 'es-ES'))
# translation result is "¿Dónde está el baño?"
string phrase = "Where is the bathroom?";

// Return the phrase as a string in the desired langage.  In this case, English to Spanish.
var translation = await Relay.Translate(this, phrase, Language.English, Language.Spanish);
// translation result is "¿Dónde está el baño?"
String phrase = "Where is the bathroom?";

// Return the phrase as a string in the desired langage.  In this case, English to Spanish.
String translation = relay.translate(phrase, LanguageType.English, LanguageType.Spanish);
// translation result is "¿Dónde está el baño?"
var phrase string = "Where is the bathroom?"

// Return the phrase as a string in the desired langage.  In this case, English to Spanish.
translation:= api.Translate(interactionUri, phrase, sdk.ENGLISH, sdk.SPANISH)
// translation result is "¿Dónde está el baño?"

To see the list of languages supported, see the Say and Listen section.