Maayan
Maayan

Reputation: 81

How to disable localizer in Bot Framework

Is there a way to completely disable the Bot Framework default localizer? The localizer seems to translate prompts inconsistently and in unexpected places. Also my bot sometimes cannot understand common user inputs (help, quit, back, yes, no) since it seems to be expecting them in a different language.

I didn't configure any localization settings so I'm guessing this behaviour is caused by the default Bot Framework localization. I'm looking for a way to completely avoid any attempts to translation and keep my bot using English only.

enter image description here

Upvotes: 3

Views: 288

Answers (1)

Nicolas R
Nicolas R

Reputation: 14589

Have a look to the dedicated section of the documentation about localization: https://learn.microsoft.com/en-us/bot-framework/dotnet/bot-builder-dotnet-formflow-localize

The bot framework is automatically using the locale from the message to select the right Resources, but you can override this information by setting your thread's CurrentUICulture and CurrentCulture, and ideally also your Locale property in your MessageActivity

CultureInfo lang = ...;
Thread.CurrentThread.CurrentCulture = lang;
Thread.CurrentThread.CurrentUICulture = lang;
context.Activity.AsMessageActivity().Locale = lang.ToString();

Don't forget to set it for each Thread that will send messages as there is no global solution to switch the language.

If you want to go deeper, you can have a look to the bot framework sources:

Edit: For the prompts part, if I remember well I had to create my own public abstract class MyPrompt<T, U> : IDialog<T> and in that one:

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;
}

Upvotes: 2

Related Questions