开发者

How do I tell my webpage to use a specific UI Culture?

开发者 https://www.devze.com 2023-01-17 08:02 出处:网络
I can tell my page to use a certain CultureInfo like System.Globalization.CultureInfo.CreateSpecificCulture(\"en-US\");

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开发者_如何学C 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:

How do I tell my webpage to use a specific UI Culture?

(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:

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


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);
0

精彩评论

暂无评论...
验证码 换一张
取 消