The following segment shows the PizzaBot equipped for autotranslation.
Important:While the Add Components menu adds template state nodes for these translation components, it doesn’t insert the autoTranslate: “boolean” variable into the context node. SourceVariable: "translated" # this variable now would holds the translated text # translate the user text and store it in the translated variable # add DetectLanguage and TranslateInput components Translated: "string" # holds the user's text that's translated into English. Because both the System.DetectLanguage and System.TranslateInput components are positioned before the System.Intent component, they enable the initial user input to be translated into English before it can be used by the System.Intent component and resolved to one of the intents. In the following snippet, the rb context variable is set, but in this PizzaBot, it’s accompanied by another variable called translated. After the input is translated and the intent is resolved to English, the resource bundles handle the rest. The following snippet shows this hybrid approach, which enables your bot to detect the user’s language. To start the session in the user’s language, you need to enable the translation service for the bot and configure the dialog flow accordingly. Keep in mind that using this approach requires users to first enter something in English (like “Hello, Pizzabot!”).
If you’re returning the user’s language from the browser, then simply setting the resource bundle variable and then referencing both it and the message key in an output component is all you need to do. The first outputs a simple string and the other uses dynamic values. Further down, value expressions define the text property for the System.Output components reference the rb variable and the keys, WhatType and OnTheWay. In the following OBotML snippet for a pizza bot, the resource bundle is declared as the variable, rb, in the context section. To set the output for a built-in component, you need to add a resource bundle context variable and then reference both it and the message key.