Question

I'm working on a asp.net web application and one of the requirements is that the user has to be able to select the language they want. I"m using Resx files to store the locals. What my question is do I need to change the CurrentCulture of the thread every time a page is loaded or is there a way to have it handled automatically when a logged in user moves from one page to the next.

Was it helpful?

Solution

Yes, I believe you need to set it every time. To make it even worse, you have to do it by overriding the InitializeCulture method of the Page class. I created a SitePage that all pages in my project inherit from instead of Page to do this.

public class SitePage : Page
{
    protected override void InitializeCulture()
    {
        base.InitializeCulture();

        // Set both the CurrentCulture (for currency, date, etc) conversion, and the CurrentUICulture for resource file lookup.
        Thread.CurrentThread.CurrentCulture = whatever;
        Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture;
    }

}

Further reading: http://msdn.microsoft.com/en-us/library/bz9tc508.aspx

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