在code编程方式更改资源文件的语言(RESX)的背后 [英] Programmatically change resource file language (resx) in Code Behind
问题描述
我在C#.Net应用程序,我有一个文件结构是这样的:
I have a .Net application in C# and I have a file structure something like:
App_LocalResources
- MyPage.aspx.resx
- MyPage.aspx.fr.resx
MyPage.aspx
MyPage.aspx.cs
我想通过编程修改它告诉它的RESX文件中使用应用程序的语言。我想这样做背后文件(MyPage.aspx.cs)在code。
I am trying to programatically change the language which tells the application which resx file to use. I want to do this in the code behind file (MyPage.aspx.cs).
我在上preRender尝试这两种,Page_Init和Page_Load中事件:
I have tried both of these in the OnPreRender, Page_Init, and Page_Load events:
Thread.CurrentThread.CurrentUICulture = new CultureInfo("fr-CA");
Thread.CurrentThread.CurrentCulture = new CultureInfo("fr-CA");
和它不工作。该页面仍显示英文。该MyPage.aspx文件中有这样的:
and it does not work. The page still shows the english language. The MyPage.aspx file has this:
<h3><asp:Literal runat="server" Text="<%$ Resources:pageTitle %>" /></h3>
请注意,我可以不关心浏览器的语言。它必须过骑这一点。我一直在寻找这种解决方案无济于事网络。所有实施例显示切换语言我已经尝试(见上文)的方式但是这并不影响使用的资源文件。任何想法?
Note that I cannot care about the browser language. It must over-ride this. I have been searching the web for this solution to no avail. All examples show switching the language the way I have already tried (above) however this does not affect the resource file used. Any ideas?
推荐答案
您必须覆盖InitializeCulture方法,并把你的code那里。例如:
You must override the InitializeCulture method and put your code there. Ex:
protected override void InitializeCulture()
{
base.InitializeCulture();
System.Threading.Thread.CurrentThread.CurrentUICulture = new CultureInfo("fr-CA");
System.Threading.Thread.CurrentThread.CurrentCulture = new CultureInfo("fr-CA");
}
希望这有助于
这篇关于在code编程方式更改资源文件的语言(RESX)的背后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!