Question

I want to be able to set the culture during runtime. For example:

protected void Page_Load(object sender, EventArgs e)
{
    Page.Culture = "fr-FR";
    Page.UICulture = "fr";
}

But that's not having any effect. I'm using resource files for translation. If I change the language of my browser it works fine, but I want the user to also be able to choose the language as well. So in this case the user wants French as the language.

Any ideas? I'm lost.

Was it helpful?

Solution

If you're creating a site where you are allowing the user to change language for example, then you need to perform this in the Global.asax file in the Application_BeginRequest method.

Each request will then have the culture set.

You simply set the following 2 lines:

    Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("fr-FR");
    Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("fr-FR");

The first line will set the number/date/etc formatting.

The second line specifies which resource localization to load - which will contain your translated content.

OTHER TIPS

You can try with this:

 Thread.CurrentThread.CurrentCulture = 
            CultureInfo.CreateSpecificCulture("en-US");
 Thread.CurrentThread.CurrentUICulture = new 
            CultureInfo("en-US");

Refer this article from MSDN for further details.

  • If you want to set it for whole application, you can set it in your Global.asax as

    Thread.Current.Culture = New System.Globalization.CultureInfo("fr-FR");

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top