ASP.NET MVC - 本地资源问题

发布于 2024-08-17 23:00:22 字数 1188 浏览 5 评论 0原文

我在尝试重写 ASP.NET MVC 中的 DisplayNameAttribute 以提供本地化字符串时遇到问题。代码本身很简单,与另一篇 Stackoverflow 帖子中的代码类似 链接文本

该代码适用于全局资源,但对于本地资源来说不太好。我有一个注册屏幕,并使用 Visual Studio“生成本地资源”命令来创建本地资源文件。生成的文件名为 Registration.aspx.resx,并且 App_LocalResources 文件夹是相对于实际的 Registration.aspx 页面创建的 - 正如人们所期望的那样。

但是,当我尝试使用以下方法获取本地化字符串时:

ResourceManager.GetString(resourceKey)

我收到以下错误消息。

找不到任何资源 适合特定文化 或中立文化。确保 “FullAssemblyName.Views.Account.App_LocalResources.Registration_aspx.resources” 已正确嵌入或链接到 编译时的程序集“FullAssemblyName” 时间,或者说所有的卫星 所需的组件是可加载的并且 已完全签署。

使用反射器,我可以看到该文件实际上是 Registration.aspx.resources 而不是 Registration_aspx.resources - 下划线/句点是细微的区别

FullAssemblyName.Views.Account.App_LocalResources.Registration.aspx.resources

我已经对代码进行了相当多的修改,但无论我做什么,所请求的文件总是与程序集中复制的文件不同。例如,如果我重命名 Registration_aspx (在生成的 Registration.aspx.designer.cs 类中,我会得到相同的错误,但这次路径是“...App_LocalResources.Registrationaspx.resources”

有人遇到过这个吗?有什么办法吗?我可以确保在我的程序集中找到的资源有这个下划线?!?!?

提前谢谢您!

I am having an issue when attempting to override the DisplayNameAttribute in ASP.NET MVC to provide a localized string. The code itself is straightforward and similar to that in another Stackoverflow post link text

The code works for global resources but not so well for local resources. I have a registration screen and used the Visual Studio "Generate Local Resource" command to create my local resource file. The generated file is named Registration.aspx.resx and the App_LocalResources folder is created relative to the actual Registration.aspx page - as one would expect.

However, when I attempt to get the localized string using:

ResourceManager.GetString(resourceKey)

I receive the following error message.

Could not find any resources
appropriate for the specified culture
or the neutral culture. Make sure
"FullAssemblyName.Views.Account.App_LocalResources.Registration_aspx.resources"
was correctly embedded or linked into
assembly "FullAssemblyName" at compile
time, or that all the satellite
assemblies required are loadable and
fully signed.

Using reflector, I can see that the file is actually Registration.aspx.resources and not Registration_aspx.resources - the underscore/period being the subtle difference

FullAssemblyName.Views.Account.App_LocalResources.Registration.aspx.resources

I have toyed with the code quite a bit but no matter what I do, the file being requested is always different than that copiled in the assembly. For instance, if i rename Registration_aspx (in the generated Registration.aspx.designer.cs class i get the same error but this time the path is "...App_LocalResources.Registrationaspx.resources"

Has anyone run into this? Is there any way I can ensure that the resource found in my assembly has this underscore?!?!?

Thank you in advance!

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

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

发布评论

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

评论(1

昵称有卵用 2024-08-24 23:00:22

尝试 Michael K. Campbell 解决方案链接文本。它对我的项目本地化效果很好。

Try Michael K. Campbell solution link text. It worked fine form me in localizing my project.

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