.resx 与数据库与提供本地化/全球化的自定义解决方案

发布于 2024-12-09 19:49:16 字数 310 浏览 1 评论 0原文

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

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

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

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

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

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. Maintainability
  2. Extensibility
  3. Performance / Scalability

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!

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

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

发布评论

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

评论(5

悲喜皆因你 2024-12-16 19:49:16

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

数据驱动本地化 资源提供程序

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

他还在此处很好地总结了这些问题(我在这里粘贴了一些好的内容 - 不是我的自己的作品!)

是否要 Resx

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

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

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

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

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

在运行时更改资源
可能看起来没什么大不了的,但是在工作期间它可以非常方便
资源本地化过程。如果可以编辑该多好
运行时资源,进行更改,然后实际看到该更改
立即在用户界面中显示吗?

使用数据库资源

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

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

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

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

  • Database driven Localization lets you store resources in a SQL Server database.
  • Interactive Web based Resource Adminstration provides a live Web based adminstration for that can edit and update resources while the app is running
  • Resource Editing Control associates icons with each localizable control and allows jumping directly to the administration form with the current resource id and locale selected.
  • Resx Import and Export lets you import existing Resx resources, interactively edit them with the data driven provider, then export them back out as Resx resources.
  • Localization Utilities like a JavaScript Resource Handler, functions to embed localized script values and much more.

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

To Resx or not to Resx

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.

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.

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 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 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.

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?

Using Database Resources

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.

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.

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.

天气好吗我好吗 2024-12-16 19:49:16

您可能知道,本地化 .Net 应用程序的默认方法(实际上是行业最佳实践)是使用资源文件(在本例中为 .resx)。如果你想使用数据库,你必须编写自己的ResourceManager。

由此看来,答案应该是显而易见的:使用标准,不要重新发明轮子。

您可能想知道为什么通过资源文件进行本地化成为行业标准。嗯,原因有很多(这里无法一一提及),其中大多数与本地化过程有关。关键是,更新(即修复或安装)数据库驱动的本地化翻译非常困难。想想安装它需要什么 - 一些 SQL 脚本。您知道如果您将其发送出去进行翻译会发生什么吗?或者甚至错误地更新了?这些类型的文件使用起来不太安全(而且它们往往非常大),因此您要么需要创建某种生成器(使用类似资源的文件作为输入,这完全无法实现目的...... )或者你需要非常小心(并祈祷翻译人员不会破坏文件)。

也就是说,数据库驱动的本地化有时是唯一明智的做法 - 这是当您需要实现所谓的动态本地化时,即允许用户翻译内容或以多种语言添加其内容。
对于静态本地化(典型场景),请使用资源文件。

As you perhaps know, default method (which is actually industry best practice) for Localizing .Net Applications is using resource files (.resx in this case). If you want to use database, you would have to write your own ResourceManager.

From this, the answer should be obvious: use standard and do not reinvent the wheel.

You might be wondering why Localization via resource files became industry-wide standard. Well, there are many reasons (too many to mention here), most of them regard to Localization process. The key one is, it is painfully hard to update (i.e. fix or install) translations for database driven Localization. Just think of what you need to install it - some SQL script. You know what will happen if you send out this for translation? Or even mistakenly update it? These kind of files are not very safe to work with (and they tend to be very large), so either you would need to create some kind of generator (with resource-like file as an input, which totally bits the purpose...) or you would need to be very careful (and pray that a translator won't break the file).

That is to say, database-driven Localization is sometimes the only sensible way of doing things - this is when you need to implement so-called dynamic Localization, that is allow users to translate things or add their contents in multiple languages.
For static Localization (typical scenario) use resource files.

彩虹直至黑白 2024-12-16 19:49:16

本地化用户界面不应存储在数据库中,最好使用标准 resx 方法,因为这将使您可以灵活地为每个客户端/部署自定义前端用户界面,而无需更改后端或存储数据库中有关每个客户定制的大量数据。

关于数据(双语数据或多语言数据),将它们存储在数据库中,并使用适合上下文的任何技术(每种语言的表格,或每种语言的重复列)。

Localizing user interface should not be stored in database, it is preferable to use the standard resx method because this will give you the flexibility to customize the user interface of front end for each client/deployment, without the need to change the back end or store much data about each client customization in database.

Regarding data (bi-lingual data or multi-lingual data) store them in database and use whatever technique suitable for the context (table per language, or duplicate columns for each language).

妳是的陽光 2024-12-16 19:49:16

对于某些不需要通过应用程序的 UI 操作的静态值,使用 resx 是最佳方法,但如果您的值需要更新,则数据库驱动将是最好的方法。对我来说,这仍然是个案的基础。但是我在互联网上看到的博客之一使 resx 文件可以通过用户界面进行更新。 http://sandblogaspnet.blogspot.com/2009/11/updating-resource-file.html..希望这对您有帮助。

using resx is the best approach for some static values that needs not to be manipulated via UI of the app but if your values needs to be updated DB driven would be the best for it. For me its still a case to case basis. But one of the blogs I have seen in the internet made the resx files updateable via user interface.. http://sandblogaspnet.blogspot.com/2009/11/updating-resource-file.html.. hope this would help you.

紫竹語嫣☆ 2024-12-16 19:49:16

由于上述所有内容都是正确的,我想添加一些额外的见解。

在处理“静态”项目/网站(例如仪表板或其他小型网站)时,我倾向于使用基于 .resx 的本地化,这些项目/网站专注于特定的用户组。

当从事更大且更“动态”的项目时,例如商店、服务产品等(特别是当内容本地化时 - 不仅仅是标签),我喜欢使用数据库本地化。

当您开发大型项目时,每种语言都由另一个人维​​护,该人不一定在您的项目中(尤其是在社区项目中)。因此,维护不同的语言变得非常麻烦。
另一方面,为用户提供一些好的/简单的 UI 来更新他们的语言也很耗时。因此,请尝试为您的项目找到一条好的路径。

As all the above are true, I want to add some additional insights.

I tend to use .resx based localisation, when working on "static" projects/websites like Dashboards or other small websites, which are focused on a specific usergroup.

When working on larger and more "dynamic" projects like shops, service-offerings, etc. (esp. when content is localized - not only labels) I like to use database localisation.

When you are developing on larger projects each language is maintained by another person, who is not necessarily in your project (especially in community-projects). Thus maintenance of different languages becomes a real hassle.
On the other side providing users some good/easy UI to update their language is time-consuming as well. So try to find a good path for your project.

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