查看文档中有关本地化的专门部分:https://docs.microsoft.com/en-us/bot-framework/dotnet/bot-builder-dotnet-formflow-localize
bot 框架会自动使用消息中的语言环境来选择正确的资源,但您可以通过设置线程的 CurrentUICulture 和 CurrentCulture 以及最好在 MessageActivity 中设置 Locale 属性来覆盖此信息
CultureInfo lang = ...;
Thread.CurrentThread.CurrentCulture = lang;
Thread.CurrentThread.CurrentUICulture = lang;
context.Activity.AsMessageActivity().Locale = lang.ToString();
不要忘记为每个将发送消息的线程设置它,因为没有切换语言的全局解决方案。
如果你想更深入,你可以看看 bot 框架源代码:
编辑:
对于提示部分,如果我没记错的话,我必须创建自己的 public abstract class MyPrompt<T, U> : IDialog<T> 并在其中:
protected virtual IMessageActivity MakePrompt(IDialogContext context, string prompt, IReadOnlyList<U> options = null, IReadOnlyList<string> descriptions = null, string speak = null)
{
var msg = context.MakeMessage();
// force Culture
CultureInfo lang = ...;
if (lang != null)
{
Thread.CurrentThread.CurrentCulture = lang;
Thread.CurrentThread.CurrentUICulture = lang;
context.Activity.AsMessageActivity().Locale = lang.ToString();
}
if (options != null && options.Count > 0)
{
promptOptions.PromptStyler.Apply(ref msg, prompt, options, descriptions, speak);
}
else
{
promptOptions.PromptStyler.Apply(ref msg, prompt, speak);
}
return msg;
}