简体   繁体   English

ASP.NET-当标记使用本地化的代码时,为什么在代码隐藏中使用默认的resx文件?

[英]ASP.NET - why is the default resx file being used in the code-behind when the localized one is being used by the markup?

I am creating an ASP.NET web application in C#, and have to localize the application into English and French. 我正在用C#创建一个ASP.NET Web应用程序,并且必须将该应用程序本地化为英语和法语。 I have created two resources files: App_GlobalResources\\Resources.resx and App_GlobalResources\\Resources.fr.resx containing the english and french content. 我创建了两个资源文件:App_GlobalResources \\ Resources.resx和App_GlobalResources \\ Resources.fr.resx,其中包含英语和法语内容。

When I run the application with my browser set to French (fr_FR), the french content is correctly displayed in the markup. 当我在浏览器设置为法语(fr_FR)的情况下运行该应用程序时,法语内容会正确显示在标记中。

Within the code-behind, when I access values from the resources, it returns the default english values only. 在后台代码中,当我从资源访问值时,它仅返回默认的英语值。 eg 例如

this.CompanyName.Text = string.Format(App_GlobalResources.Resources.CompanyLocationsFormat, companyName); this.CompanyName.Text = string.Format(App_GlobalResources.Resources.CompanyLocationsFormat,companyName);

Debugging the app shows that the CurrentCulture and CurrentUICulture are both correctly set to fr_FR. 调试该应用程序将显示CurrentCulture和CurrentUICulture都正确设置为fr_FR。

Can anyone explain how I can get the code-behind to use the culturally-appropriate resource file? 谁能解释我如何获取背后的代码以使用适合当地文化的资源文件?

Many thanks 非常感谢

(C#, ASP.NET 3.5 SP1, Visual Studio 2008, IE 8.0.7600) (C#,ASP.NET 3.5 SP1,Visual Studio 2008,IE 8.0.7600)

Are you certain that this specific resource (CompanyLocationsFormat) exists in the french resources file? 您确定法语资源文件中存在此特定资源(CompanyLocationsFormat)吗? If a resource is missing, it will fall back to the default one. 如果缺少资源,它将恢复为默认资源。

在web.config的<system.web>部分中是否有此功能?

<globalization culture="auto" uiCulture="auto" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM