问题
I am trying to do confirm prompt the user based on the user's prefered locale. but V4 bot prompting user in English as well eventhough Locale is spanish.
Here is my code in v4 node:
const { ConfirmPrompt } = require('botbuilder-dialogs');
const CONFIRM_PROMPT_ES = 'confirmPrompt_ES';
const CONFIRM_PROMPT_EN = 'confirmPrompt_EN';
// added dialogs to dialogSet
this.addDialog(new ConfirmPrompt(CONFIRM_PROMPT_ES,false,**'es-mx'**))
.addDialog(new ConfirmPrompt(CONFIRM_PROMPT_EN))
if(constant.lang==='es'){
console.log('---entered into spanish prompt block---');
stepContext.context.activity.locale='es-mx';
return await stepContext.prompt(CONFIRM_PROMPT_ES, { prompt: constant.liketostorevin });
}
else{
console.log('---entered into english prompt block---');
return await stepContext.prompt(CONFIRM_PROMPT_EN, { prompt: constant.liketostorevin });
}
Please let me know if anyone know the way how to handle. thanks in advance.
回答1:
This is a bug, of sorts, related to the locale value being passed in. Presently, the locale needs to be formatted as culture + locale and lowercase (e.g. 'fr-fr'). If you pass in only the culture or upper case locale (e.g. 'fr', 'FR', or 'en-FR'), then the prompt defaults to 'en-us'.
Make this adjustment, and you should be good to go. Please note, the defaultLocale option for ConfirmPrompt is only read if no locale is specified in the activity. Otherwise, it is ignored.
For reference, this was logged as an issue here with a matching fix in this PR.
Hope of help!
回答2:
I made below changes to my code. Now bot able to prompt the confirmation as per locale.
var confPrompt=new ConfirmPrompt(CONFIRM_PROMPT_ES,false,'es-mx');
**confPrompt.confirmChoices= ['Sí', 'No']**
this.addDialog(confPrompt)
.addDialog(new ConfirmPrompt(CONFIRM_PROMPT_EN))
return await stepContext.prompt(CONFIRM_PROMPT_ES, { prompt: constant.liketostorevin });
Hope this will be helpful to someone like me :)
来源:https://stackoverflow.com/questions/57655648/how-to-implement-confirm-prompt-default-locale-in-node-bot-v4