Unable to change language for entire bot

In my ‘langauge’ journey it gets changed to hindi. But if I invoke other journeys then english language is used. How can I solve this?

Hi @akshay , did you set the targetLanguage to hindi in the main function ?

Yes, this is my main function

app.customOptions = {
minConfidence: 0.7,
i18n: true
}

app.memory.get(‘botLanguage’).then((targetLanguage) => {
if (targetLanguage) {
app.customOptions.targetLanguage = targetLanguage;
}
}, (error) => {
app.customOptions.targetLanguage = ‘en’;
});

return app.start(app.customOptions);

I think issue is in your code, @akshay. In your main function, use the following code:

app.customOptions = {
minConfidence: 0.7,
i18n: true
}

app.memory.get(‘botLanguage’).then((targetLang) => {
return app.start({…app.customOptions, targetLanguage:targetLang});
}).catch((error) => {
return app.start({…app.customOptions, targetLanguage:‘en’});
});

Still, it’s not changing. I have a ‘language’ journey and in response, I’m calling this function

return new Promise(resolve => {
// Your logic goes here
let userChoice = app.context.steps[‘language’];

let language= '';
if(userChoice === 'English') {
    language = 'en';
} else {
    language = 'hi';    
}

app.options.targetLanguage = language;
app.memory.set('botLangauge', language).then(() => {
    app.sendTextMessage(app.renderMessage('language-selected', {}, `Language has been changed to ${language} for you!`)).then(() => {
        resolve();
    });
});

});

Also, I’d configured every other journey in Hindi too

@akshay, I have to see the bot flow to identify the issue. So, Can you give me admin access to the bot ? ( My Email: amudhan@yellowmessenger.com )

Once this is done, You can revoke my access anytime.

2 Likes

Okay @Amudhan_S . I’d sent you the admin access invite

1 Like

Hey @akshay , I have made some changes and now your bot changes the language according to the user input in all journeys.

Changes I have made:

  1. In the languageValidator function, I have set the bot’s Target Language and I have set the memory value.

  2. Another small change is, Inside your changeLanguageAction function, I have replaced app.renderMessage() with just app.sendTextMessage().

Note:

  1. I am not sure Why you have been setting the step value inside the languageValidator function. Only After setting the value, it comes to this function. So there is no need to set the current step’s value after you get it right ?

  2. Once you get the language step value, you can set the memory value in the languageValidator function. You don’t have to wait and set the memory value in the changeLanguageAction function which is the response of the language journey.

  3. In the changeLanguageAction function, you have used app.renderMessage(). I am not sure whether we can able to send a variable value inside the app.renderMessage() since app.renderMessage() is used just to send a response (a response that is gonna be same and gonna be used many times) to the user. You can use app.sendTextMessage() instead. If you still want to use app.renderMessage(), then make sure to configure all the responses you may need in the localization tab.

2 Likes

Okay, I got it. I’ll check with app.renderMessage(). Thank you :slight_smile: @Amudhan_S

2 Likes

Thank you @Amudhan_S for this detailed answer and helping a fellow community member. :tada:

1 Like