加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net – .resx vs数据库vs用于提供本地化/全球化的自定义解决

发布时间:2020-12-15 18:52:17 所属栏目:asp.Net 来源:网络整理
导读:在我的办公室,我们对本地化/全球化以及如何处理它的长期争论。一方面推动内置到ASP.NET的资源(.resx)文件路由,一方面推动数据库驱动的解决方案。第三组相信滚动定制解决方案。 当然,每种方法都有自己独特的优点和缺点 – 我们一次又一次地讨论过,没有达
在我的办公室,我们对本地化/全球化以及如何处理它的长期争论。一方面推动内置到ASP.NET的资源(.resx)文件路由,一方面推动数据库驱动的解决方案。第三组相信滚动定制解决方案。

当然,每种方法都有自己独特的优点和缺点 – 我们一次又一次地讨论过,没有达成真正的共识。

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

>可维护性
>可扩展性
>性能/可扩展性

除了只是建议,我们也会对任何开源项目感兴趣,这可能有助于简化问题,以及。谢谢!

解决方法

Rick Strahl(一个MS MVP)有一个伟大的工具包,用于通过DB管理本地化 – 提供了通过受控环境更新和修改需求的能力,并为您做了大量的繁重工作。 Histoolkit提供以下功能:

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

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

他还总结了问题非常好here(Ive粘贴了一些好的位 – 这不是我自己的工作!)

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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读