.resx vs 数据库 vs 提供本地化/全球化的自定义解决方案 [英] .resx vs database vs custom solution for providing Localization/Globalization

查看:26
本文介绍了.resx vs 数据库 vs 提供本地化/全球化的自定义解决方案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的办公室,我们就本地化/全球化以及如何处理它进行了长期的辩论.一方面推动 ASP.NET 内置的资源 (.resx) 文件路由,另一方面推动数据库驱动的解决方案.第三组相信推出自定义解决方案.

At my office, we have had a long-standing debate about Localization/Globalization and how to handle it. One side pushes for the Resource (.resx) file route built in to ASP.NET, one side pushes for a database driven solution. A third group believes in rolling a custom solution.

当然,每种方法都有其独特的优点和缺点 - 我们已经反复讨论过,但从未达成真正的共识.

Of course, each method has its own unique benefits and disadvantages - and we've discussed it over and over, without ever coming to a real consensus.

因此,我向社区提出:根据您的经验,随着应用程序的增长,哪种方法可以提供以下最佳组合:

So, I pose it to the community: in your experience, which method provides the best mix of the following as the application grows:

  1. 可维护性
  2. 可扩展性
  3. 性能/可扩展性

除了建议之外,我们还对任何可能有助于简化问题的开源项目感兴趣.谢谢!

In addition to just advice, we'd also be interested in any open source projects which might help to simplify the question, as well. Thanks!

推荐答案

Rick Strahl(MS MVP)有一个很棒的工具包,用于通过数据库管理本地化 - 提供通过受控环境按需更新和修改的能力,并且为您完成大部分繁重的工作.Histoolkit 提供以下功能:

Rick Strahl (An MS MVP) has a great tool kit for managing localization via the DB - offer the ability to update and modify on demand through a controlled environment and does much of the heavy lifting for you. Histoolkit offer the following features:

数据驱动的本地化资源提供者

Data Driven Localization Resource Provider

  • 数据库驱动的本地化可让您将资源存储在 SQL Server 数据库中.
  • 基于 Web 的交互式资源管理提供基于 Web 的实时管理,可以在应用运行时编辑和更新资源
  • 资源编辑控件将图标与每个可本地化的控件相关联,并允许直接跳转到选择当前资源 ID 和区域设置的管理表单.
  • Resx 导入和导出可让您导入现有的 Resx 资源,与数据驱动的提供程序交互地编辑它们,然后将它们导出为 Resx 资源.
  • 本地化实用程序,例如 JavaScript 资源处理程序、嵌入本地化脚本值的函数等等.

他也很好地总结了这些问题这里(我在这里粘贴了一些好的部分- 不是我自己的作品!)

He also summarises the issues very well here (Ive pasted some good bits here - not my own work!)

Resx 还是不Resx

.NET 中的默认资源存储机制使用基于 Resx 的资源.resx 指 XML 的文件扩展名用作本机资源的原始输入的文件.网.虽然 XML 是您在 Visual 中看到的输入存储格式Studio 和 .Resx 文件,最终资源格式为二进制被编译成 .NET 程序集的格式 (.Resources)编译器.这些编译的资源可以与二进制程序集中的代码或资源卫星中的代码其唯一目的是提供资源的集会.通常在.NET 将 Invariant 文化资源嵌入到基础中与存储在卫星组件中的任何其他培养物组装在特定文化的子目录中.

The default resource storage mechanism in .NET uses Resx based resources. Resx refers to the file extension of XML files that serve as the raw input for resources that are native to .NET. Although XML is the input storage format that you see in Visual Studio and the .Resx files, the final resource format is a binary format (.Resources) that gets compiled into .NET assemblies by the compiler. These compiled resources can be stored either alongside with code in binary assemblies or on their own in resource satellite assemblies whose sole purpose is to provide resources. Typically in .NET the Invariant culture resources are embedded into the base assembly with any other cultures housed in satellite assemblies stored in culture specific sub-directories.

如果您使用的是 Visual Studio资源编译过程几乎是自动的——当你将 .Resx 文件添加到项目 VS.NET 会自动编译资源并将它们嵌入到程序集中并创建卫星程序集以及每个所需的目录结构支持的语言环境.ASP.NET 2.0 进一步扩展了这个基本过程自动化资源服务模型并自动编译找到的 Resx 资源 App_GlobalResources 和App_LocalResources 并通过特定于 ASP.NET 的资源提供程序.资源提供者在 ASP.NET 中使资源访问更容易、更一致应用程序.

If you’re using Visual Studio the resource compilation process is pretty much automatic – when you add a .Resx file to a project VS.NET automatically compiles the resources and embeds them into assemblies and creates the satellite assemblies along with the required directory structure for each of the supported locales. ASP.NET 2.0 expands on this base process by further automating the resource servicing model and automatically compiling Resx resources that are found App_GlobalResources and App_LocalResources and making them available to the application with a Resource Provider that’s specific to ASP.NET. The resource provider makes resource access easier and more consistent from within ASP.NET apps.

.NET 框架本身使用 .Resx 资源来提供服务本地化的内容,因此这些工具似乎很自然框架提供了使资源创建工具可用于服务同样的型号.

The .NET framework itself uses .Resx resources to serve localized content so it seems only natural that the tools the framework provides make resource creation tools available to serve this same model.

Resx 运行良好,但不够灵活当涉及到实际编辑资源时.工具支持在Visual Studio 确实不足以支持本地化因为 VS 没有提供一种简单的方法来交叉引用资源跨多个地区.尽管 ASP.NET 的设计编辑器可以提供帮助最初为页面上的所有控件生成资源 - 通过生成本地资源工具 - 它仅适用于默认不变文化 Resx 文件.

Resx works well enough, but it’s not very flexible when it comes to actually editing resources. The tool support in Visual Studio is really quite inadequate to support localization because VS doesn’t provide an easy way to cross reference resources across multiple locales. And although ASP.NET’s design editor can help with generating resources initially for all controls on a page – via the Generate Local Resources Tool – it only works with data in the default Invariant Culture Resx file.

Resx 资源也是静态的– 它们毕竟被编译成一个程序集.如果你想做对资源的更改需要重新编译才能看到这些更改.ASP.NET 2.0 引入了可以存储的全局和本地资源在服务器上并且可以动态更新 - ASP.NET 编译器实际上可以在运行时编译它们.但是,如果您使用预编译的 Web 部署模型,资源最终仍然是静态的,不能在运行时更改.所以一旦你完成了编译资源是固定的.

Resx Resources are also static – they are after all compiled into an assembly. If you want to make changes to resources you will need to recompile to see those changes. ASP.NET 2.0 introduces Global and Local Resources which can be stored on the server and can be updated dynamically – the ASP.NET compiler can actually compile them at runtime. However, if you use a precompiled Web deployment model the resources still end up being static and cannot be changed at runtime. So once you’re done with compilation the resources are fixed.

在运行时更改资源可能看起来没什么大不了,但在资源本地化过程.如果你能编辑不是很好吗运行时的资源,进行更改,然后实际看到该更改立即在 UI 中?

Changing resources at runtime may not seem like a big deal, but it can be quite handy during the resource localization process. Wouldn’t it be nice if you could edit resources at runtime, make a change and then actually see that change in the UI immediately?

使用数据库资源

这使我将资源存储在数据库.数据库本质上更具动态性,您可以使无需重新编译数据库即可更改数据库中的数据应用.此外,数据库数据更容易在之间共享多个开发人员和本地化人员,因此更容易进行更改团队环境中的资源.

This brings me to storing resources in a database. Databases are by nature more dynamic and you can make changes to data in a database without having to recompile an application. In addition, database data is more easily shared among multiple developers and localizers so it’s easier to make changes to resources in a team environment.

当您考虑资源时编辑它基本上是一个数据输入任务——你需要查找单个资源值,查看所有不同的语言变体然后添加和编辑每个不同语言环境的值.虽然所有这些都可以通过 Resx 文件中的 XML 来完成直接构建数据库的前端实际上要容易得多而不是散落在各处的 XML 文件.数据库还为您提供更灵活地在不同视图中显示资源数据并且可以轻松执行批量更新和重命名密钥等操作和价值观.

When you think about resource editing it’s basically a data entry task – you need to look up individual resource values, see all the different language variations and then add and edit the values for each of the different locales. While all of this could be done with the XML in the Resx files directly it’s actually much easier to build a front end to a database than XML files scattered all over the place. A database also gives you much more flexibility to display the resource data in different views and makes it easy to do things like batch updates and renames of keys and values.

好消息是 .NET 中的资源方案是不固定,您可以扩展它们..NET 和 ASP.NET 2.0 允许您创建自定义资源管理器(核心 .NET 运行时)和资源提供者(ASP.NET 2.0)从任何地方提供资源,包括一个数据库.

The good news is that the resource schemes in .NET are not fixed and you can extend them. .NET and ASP.NET 2.0 allow you create custom resource managers (core .NET runtime) and resource providers (ASP.NET 2.0) to serve resources from anywhere including out of a database.

这篇关于.resx vs 数据库 vs 提供本地化/全球化的自定义解决方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆