Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
361 views
in Technique[技术] by (71.8m points)

asp.net - .resx vs database vs custom solution for providing Localization/Globalization

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!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

Just Browsing Browsing

[5] html - How to create even cell spacing within a

1.4m articles

1.4m replys

5 comments

57.0k users

...