MVC3 的资源文件命名问题 - 无法自动生成隐藏代码

发布于 2025-01-01 13:24:11 字数 399 浏览 3 评论 0原文

我有一个使用 Razor 的 MVC3 应用程序。我想将应用程序本地化为各种语言,因此我添加了 App_LocalResources 文件夹并添加了资源文件,如下所示:

Index_cshtml.en-US.resx

Index_cshtml.en-GB.resx

但是,当我将资源文件上的代码生成设置为公共时,代码文件已创建但为空。如果我将文件重命名为 Index_cshtml_en-GB.resx,它会自动正确生成后面的代码,因此看起来 MVC 无法处理其命名约定中的“.en-GB”或“.en-US”。然而,这并不是 ASP.NET 应用程序根据区域性集了解要使用哪个资源文件的关键方式。

我确实在 ASP.NET Webform 应用程序中使用过无数次,这对于 MVC 来说有什么不同吗?

I have an MVC3 application using Razor. I want to localise the application for various languages so I added a App_LocalResources folder and added a resource files as follows:

Index_cshtml.en-US.resx

Index_cshtml.en-GB.resx

However when I set the code generation on the resource files to public, the code file is created but is empty. If I rename the file to Index_cshtml_en-GB.resx it auto generates the code behind correctly so it looks as if MVC cannot handle the '.en-GB' or '.en-US' in its naming convention. However isn't that the key way an ASP.NET application knows which resource file to use based on the culture set.

I've certainly used this countless times in ASP.NET webform applications, is it different for MVC?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我做我的改变 2025-01-08 13:24:11

对于此类问题,迭代方法可能效果最好。首先你可能想尝试(注意使用 . 而不是 _)

Index.cshtml.resx

,一旦成功就尝试

Index.cshtml.en.resx or Index.cshtml.en-US.resx

For problems like this an iterative approach might work best. First you might want to try (note the use of . instead of _)

Index.cshtml.resx

and once that's working then try

Index.cshtml.en.resx or Index.cshtml.en-US.resx
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文