Change Bot Language

Hi, how can I change the bot language from English into Arabic in an action. I tried to set the following 2 variables to ‘ar’: event.nlu.language & event.state.user.language = ‘ar’
and pushed the ‘ar’ value to pot languages, but it doesn’t work.

Here is my action

Hey @Fatma!

You only need to set event.state.user.language = ‘ar’

See an example here:

If it still does not work, please let me know.

Have a nice day!

Hi @spgin,

Thanks for your response.
I got an error when I am trying to do that.

Here are my action and the error appeared:

Hey @Fatma,

You need to remove the duplicated action(bp: typeof sdk, ...) function declarations.
Only the first declaration is necessary.

Ooh thanks @spgin , I didn’t notice that.
But the same error still appears, after removing the duplicated line.

Please paste your action’s code below. This will help me debug it.

Here is my action’s code:

async function action(bp: typeof sdk, event: sdk.IO.IncomingEvent, args: any, { user, temp, session } = event.state){
/** Your code starts below */


  • Update user language
  • @title Update user language
  • @category Language
  • @author Botpress, Inc.
    const myAction = async () => {
    event.state.user.language = ‘ar’
    await event.setFlag(bp.IO.WellKnownFlags.FORCE_PERSIST_STATE, true)

return myAction()
/** Your code ends here */

The error is solved but the used language didn’t change:

Is the ar language available in your Botpress instance? You can see which languages are installed from the Admin page.

@Fatma You will see the configured language in event.state.user.language:

Detected language is what the NLU engine detected (based on the last 3 messages), and Used language will be the value of the detected language if it is available on the bot, or it will be the default language

For example, if it detects spanish but your bot only supports english and french, detected language will be spanish but used language will be english.

The language used to render elements is the value stored in event.state.user.language

You could use the value of event.nlu.detectedLanguage or event.nlu.language to set the user’s language in event.state.user.language

Maybe we could add a “User Language” field on the summary ?