在我的asp.net应用程序中,我想让用户更改他的配置文件语言,然后加载相应的resx文件 .
我有两个全局.resx文件:
LocalizedText.resx
LocalizedText.pl.resx
protected void Page_Load(object sender, EventArgs e)
{
...
if (!IsPostBack)
{
setUserSettings(...)
}
}
和
private void setUserSettings(...)
{
...
Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("pl");
}
当用户更改其配置文件设置时,也会使用 setUserSettings(...)
.
问题是它总是回退到 LocalizedText.resx
文件而不是加载 LocalizedText.pl.resx
我对它进行了重写,在Page_Load的开头,CurrentUICulture始终是“en_US” .
我试图设置UICulture和Culture属性,但它没有用 .
当我使用Page.Culture =“auto”时,当我将浏览器语言设置为“pl”时,它会加载.pl.resx文件,但这不是我想要的 .
有任何想法吗?谢谢
1 回答
我认为你应该覆盖Page
InitializeCulture
方法并在那里设置CurrentUiCulture
. 有关详细信息,请参阅:http://msdn.microsoft.com/en-us/library/system.web.ui.page.initializeculture.aspx