在 mvc 3 应用程序中组织 .resx 文件

发布于 2024-12-17 13:08:36 字数 525 浏览 4 评论 0原文

我有一个关于在 mvc3 应用程序中组织 .resx 文件的问题。到目前为止,我已成功执行以下操作:

  • 在资源解决方案中创建新的类库并添加两种语言的资源。例如,当我有以下内容时,一切正常:

Resources.resx //default language Resources.en.resx //英语语言

但我想在我的类库中有这样的组织:

DefaultLanguage foder - Resources.resx

文件夹 - Resources.en.resx

我想按文件夹组织资源。我认为它更适合翻译网站的人,而且也更易于维护。当我以这种方式组织资源时,网页返回错误...找不到错误。我错过了什么吗?我知道您不应该在命名空间中使用文件夹名称,因为这意味着视图中的引用资源依赖于文件夹名称,这是不正确的。

关键是我希望资源具有相同的行为,无论它们是否组织在文件夹中......

顺便说一句:我在网上检查并找不到任何合适的解决方案。

谢谢您的回答!

I have a question about organizing .resx files in mvc3 application. So far I have managed to do the following:

  • Creating new class library in a solution for resources and adding resources for two languages. Everything works fine when I have for example:

Resources.resx //default language
Resources.en.resx //english language

But I want to have such organization in my class library:

DefaultLanguage foder
- Resources.resx

en folder
- Resources.en.resx

I want to organize resources by folders. I think it is more appropriate for people who will translate the site and it is also more maintainable. When I organize resources in such a way the web page returns an error...cannot find error. Am I missing something? I know that you should not have folder name in namespace because that would mean that referencing resource in View is dependent on folder name and this is not correct.

The point is I would like to have the same behaviour of resources wheter they are organized in folders or not...

By the way: I check on the web and could not find any appropriate solution.

Thank you for your answers!

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

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

发布评论

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

评论(1

∞梦里开花 2024-12-24 13:08:36

MVC3 使用 ASP.NET 资源管理。有关详细信息,请参阅 ASP.NET 文档。如果您想依赖 ASP.NET 行为并生成强类型类,则必须将默认语言的资源文件和其他语言特定的资源文件放在一起。

要具有与您建议的相同的树结构,您必须实现自己的资源管理。您可能不想这样做,因为(至少某些)资源编辑工具依赖于这种行为。

在我们的项目中,我们为每个视图提供一个资源(及其翻译)。它们位于 MVC3 项目内的 Localization 文件夹中。在里面我们保留与 Views 文件夹中相同的树结构。这或多或少与 ASP.NET 本地资源的组织方式相同。常用字符串保存在 Localization 文件夹根目录下的一个 .resx 文件中。这保证了可维护性。

为了让您的翻译人员满意,您必须选择好的 .resx 编辑工具。

MVC3 uses ASP.NET resource management. See ASP.NET documentation for details. If you want to rely on ASP.NET behaviour and generated strongly typed classes, then you must keep resource file from default language and other language specific resource files together.

To have the same tree structure that you suggested, then you have to implement your own resource management. You probably don't want to do that, because (at least some) resource editing tools rely on that behaviour.

On our projects we have one resource (and his translations) for each view. They are in folder Localization within MVC3 project. Inside we keep the same tree structure as is within Views folder. This is more or less the same as ASP.NET local resources are organized. Common strings are kept in one .resx file on root of Localization folder. This ensures maintainability.

To keep your people that will do translation happy you have to pick good .resx editing tool.

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