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:
(source: balexandre.com )
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:
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);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.