是否可以使用C#在Microsoft Bot框架中开发本地化?
问题描述:
我想要一个支持多种语言的机器人.我知道通过本地化是可能的.但是我找不到使用c#的解决方案. Microsoft Bot框架文档中有一篇有关本地化的文章. 有一个关于node.js的例子.但是我正在用C#实现.因此,任何人都可以给我一个想法或任何参考,以便我可以在c#中实现本地化吗?
I want a bot that supports multiple languages. I know that it is possible through localization. But I can't find a solution for using c#. There is an article regarding localization in Microsoft Bot framework docs. There is example with node.js. But I am implementing in c#. So, can anyone give me an idea or any reference through which I'll be able to implement localization in c#?
答
在您的Startup类中:
in your Startup class:
public void ConfigureServices(IServiceCollection services)
{
services.AddLocalization();
}
在您的机器人课程中:
protected override async Task OnMessageActivityAsync(ITurnContext<IMessageActivity> turnContext, CancellationToken cancellationToken)
{
BotResource.CultureInfo = new CultureInfo("en-GB");
//OR
BotResource.CultureInfo = new CultureInfo(turnContext.Activity.Locale);
}