ASP.net is not using other locale resource files

扶醉桌前 提交于 2019-12-05 07:27:11

Try setting UICulture="auto" and Culture="auto" in the @ Page directive in your .aspx file.

How to: Set the Culture and UI Culture for ASP.NET Web Page Globalization

Or, you can accomplish the same thing in the web.config, except it would apply to every page:

<system.web>
    <globalization uiCulture="auto" culture="auto" />
</system.web>

By default the browser language doesn't affect the application locale. You need to add some code to achieve this. One way is to add some code in Global.asax or a HttpModule, on BeginRequest.

To read the language setting from the browser you can use something along the lines of:

var languages = Request.UserLanguages
if (languages != null)
{
    var lang = languages[0];
    Thread.CurrentThread.CurrentUICulture = new CultureInfo(lang);
}

If you want to also affect the datetime, number formats etc, then also set CurrentCulture.

Thread.CurrentThread.CurrentCulture = new CultureInfo(lang);

I don't believe that the ASP.NET runtime by default sets the processing thread's UI culture. You have to explicitly assign it. You can do this with your own custom HttpModule, or even in your Global.asax.cs.

Something along the lines of:

string selectedCulture = browserPreferredCulture;
Thread.CurrentThread.CurrentUICulture = new
  CultureInfo(selectedCulture);
Thread.CurrentThread.CurrentCulture =
  CultureInfo.CreateSpecificCulture(selectedCulture);

See http://msdn.microsoft.com/en-us/library/bz9tc508.aspx for an example as a starting point.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!