Tuesday, March 31, 2009

Setting Language/Culture in Using Global Resource Files



Setting Language/Culture in Using Global Resource Files


In this short post, in the code of an aspx page, we want to make the page to use our global resource file called UI.fr-CA.resx that is in Canadian French (fr-CA).

In order to this, just open the source code of the page (or the source code of the super class of your page class) and override its InitializeCulture method as in the following:

protected override void InitializeCulture()
{
Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("fr-CA");
Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("fr-CA");
base.InitializeCulture();
}



There is a good point in the above code: it works even if your controls or user controls located in the page have processes in threads different from the current thread!

No comments:

Post a Comment