Skip to main content

Apply Custom Locale to Chatbot

You can set up a conversation flow to control the language of your chatbot response. This feature is called custom locale. The following object will be used in the application of custom locale:

Expected Outcome

When user types a keyword to indicate a switch to a specific language (i.e. "English"), the subsequent chatbot response will be changed to that specific locale group (i.e. "en").

Locale switch on WhatsApp
Locale switch on WhatsApp

Sample Tree Structure

Custom Locale Sample Tree Structure
Custom Locale Sample Tree Structure

Create a Tree Node - "Language Switch - Success"

  1. Before creating this Tree Node, you should set up any specific language you want to use in Stella. To do so, please follow this guide. In this standard procedure, you should set up "en" and "zh-HK" locale groups.
Locale under Settings
Locale under Settings
  1. In Bot Builder, create a Tree Node for informing user that the chatbot language has been switched successfully. You can rename is as "Language Switch - Success".

  2. Create a new response. Create a text message to inform users that the chatbot language has been switched. This will be the fallback language in case the system fails to recognize a language.

Default Locale Message
Default Locale Message
  1. Open the "Platform Tab", select "+ Add Locale Group" under "Default*.
Add Locale Group
Add Locale Group
  1. Select the locale group you have previously created in settings.
Chinese Locale Group
Chinese Locale Group
  1. In the new locale group, enter the same text in the corresponding language.
Chinese Text
Chinese Text
  1. Now you can repeat Step 4-6 create one more locale group for "en". As a result, now you have a default locale and other locale groups under the same response.
Locale Groups Created
Locale Groups Created
  1. Save this response and Tree Node.

Create a Global Node - "Chinese Switch Global"

  1. Create a Global Node and rename is as "Chinese Switch Global". This node is to trigger the custom locale action for switching the chatbot language to the "zh-HK" locale.

  2. Create a Trigger with a specific keyword. You can use "Chinese" or "δΈ­ζ–‡".

Trigger for Chinese Switch
Trigger for Chinese Switch
  1. Create an Action with the following code:
return new Promise((resolve) => {
this.member.customLocale = "zh_HK"
resolve({ member: this.member })
})
Action for Chinese Switch
Action for Chinese Switch

::: tip If you wish to change to another locale, you may change the array behind this.member.customLocale in the code. You may check for the Supported Locale. :::

  1. Toggle on the redirect to the Tree Node - "Language Switch - Success".
Redirect to Language Switch - Success
Redirect to Language Switch - Success

Create a Global Node - "English Switch Global"

  1. Create a Global Node and rename is as "English Switch Global". This node is to trigger the custom locale action for switching the chatbot language to the "zh-HK" locale.

  2. Create a Trigger with a specific keyword. You can use "English".

Trigger for English Switch
Trigger for English Switch
  1. Create an Action with the following code:
return new Promise((resolve) => {
this.member.customLocale = "en"
resolve({ member: this.member })
})
Action for English Switch
Action for English Switch
tip

If you wish to change to another locale, you may change the array behind this.member.customLocale in the code.

  1. Toggle on the redirect to the Tree Node - "Language Switch - Success".
Redirect to Language Switch - Success
Redirect to Language Switch - Success
  1. Test your chatbot and see if you can get the expected outcome.