views:

34

answers:

2

I can tell my page to use a certain CultureInfo like

System.Globalization.CultureInfo.CreateSpecificCulture("en-US");

The code above only set's the CultureInfo, not the UICulture, how can I tell the Page to bypass what the browser says and use a specific one, so all GlobalResource's could be applied to the correct culture?

in the code above and having Swedish as my first browser language I get:

System.Globalization.CultureInfo.CurrentUICulture.Name --> sv-SE
System.Globalization.CultureInfo.CurrentCulture.Name --> en-US

I need to set the CurrentUICulture so all localization is made, in this case, in English and not Swedish, like browser is set to:

alt text

+1  A: 

There's an example on the MSDN website that explains how to do this: How to: Set the Culture and UI Culture for ASP.NET Web Page Globalization

Essentially you can set the CurrentCulture and CurrentUICulture properties of the currently executing thread (see the article for the full code example, this is an extract):

Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(selectedLanguage);
Thread.CurrentThread.CurrentUICulture = new CultureInfo(selectedLanguage);
dariom
+2  A: 

Try

System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture("en-US");
System.Threading.Thread.CurrentThread.CurrentUICulture = System.Globalization.CultureInfo.CreateSpecificCulture("en-US");

I tried it in OnInit of my page and it loaded the resources properly.

EDIT: or you could try setting it in the web.config as shown here:

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

Steve Danner
That's the current thread, if I'm using more than one thread to process stuff, I need to set it every time I create a new thread :o( was trying to get something in Page wide or Application wide (without using the web.config, maybe the global.asax)
balexandre
you're right about that. See my edit. I found a good link on MSDN showing how you can set it in the web.config.
Steve Danner
Steve, maybe you didn't read the comment well, I need **without** being in the web.config ! I know how easy is to set up the Page declaration, in Page and in Web.Config, but I want programmatically
balexandre