2
votes

I am trying to achieve localization in bot framework (C#) and have found some resources for it too.

For form flow -> https://docs.microsoft.com/en-us/bot-framework/dotnet/bot-builder-dotnet-formflow-localize

For prompt dialogs and normal messages -> https://github.com/Microsoft/BotBuilder-Samples/tree/master/CSharp/demo-ContosoFlowers#localization

But the main problem here is that, both these depend on the Thread.CurrentThread.CurrentUICulture value. Testing it out in emulator was easy by setting the locale ( How to verify if localization is working correctly in Bot framework ), but how will it be set in case of a real user accessing it through a channel.

In case CurrentUICulture is not the right way, how can we achieve localization? Is setting it in state another viable option?

https://docs.microsoft.com/en-us/bot-framework/nodejs/bot-builder-nodejs-localization provides localization documentation for nodejs, is there any similar approach to determine the locale by prompting the user in Bot framework C# SDK

Any code samples would be really helpful.

1

1 Answers

2
votes

It's not necessary to prompt the user using the dotnet SDK, it should automatically set the current culture to that of the incoming message.

You can see this working here: https://github.com/Microsoft/BotBuilder/search?utf8=%E2%9C%93&q=localizedscope&type=

If you want to ignore the user locale, and instead prompt the user to pick a language, you can see a sample of this in action here: https://github.com/EricDahlvang/ChooseLanguageBot

The jist of building a language picker is that you need to create a dialog inheriting from IDialog<object> which sends a PromptDialog with valid language options if a language hasn't been chosen already. once the user picks a language then save the locale chosen locale. You can use the context to store it: context.PrivateConversationData.SetValue("SOME_KEY", optionSelected.Locale);