問題描述
在我的辦公室,我們就本地化/全球化以及如何處理它進行了長期的辯論.一方面推動 ASP.NET 內(nèi)置的資源 (.resx) 文件路由,另一方面推動數(shù)據(jù)庫驅(qū)動的解決方案.第三組相信推出自定義解決方案.
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.
當然,每種方法都有其獨特的優(yōu)點和缺點 - 我們已經(jīng)反復討論過,但從未達成真正的共識.
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.
因此,我向社區(qū)提出:根據(jù)您的經(jīng)驗,隨著應用程序的增長,哪種方法可以提供以下最佳組合:
So, I pose it to the community: in your experience, which method provides the best mix of the following as the application grows:
- 可維護性
- 可擴展性
- 性能/可擴展性
除了建議之外,我們還對任何可能有助于簡化問題的開源項目感興趣.謝謝!
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)有一個很棒的工具包,用于通過數(shù)據(jù)庫管理本地化 - 提供通過受控環(huán)境按需更新和修改的能力,并且為您完成大部分繁重的工作.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:
數(shù)據(jù)驅(qū)動的本地化資源提供者
Data Driven Localization Resource Provider
- 數(shù)據(jù)庫驅(qū)動的本地化可讓您將資源存儲在 SQL Server 數(shù)據(jù)庫中.
- 基于 Web 的交互式資源管理提供基于 Web 的實時管理,可以在應用運行時編輯和更新資源
- 資源編輯控件將圖標與每個可本地化的控件相關聯(lián),并允許直接跳轉(zhuǎn)到選擇當前資源 ID 和區(qū)域設置的管理表單.
- Resx 導入和導出可讓您導入現(xiàn)有的 Resx 資源,與數(shù)據(jù)驅(qū)動的提供程序交互地編輯它們,然后將它們導出為 Resx 資源.
- 本地化實用程序,例如 JavaScript 資源處理程序、嵌入本地化腳本值的函數(shù)等等.
他也很好地總結(jié)了這些問題這里(我在這里粘貼了一些好的部分- 不是我自己的作品!)
He also summarises the issues very well here (Ive pasted some good bits here - not my own work!)
Resx 還是不Resx
.NET 中的默認資源存儲機制使用基于 Resx 的資源.resx 指 XML 的文件擴展名用作本機資源的原始輸入的文件.網(wǎng).雖然 XML 是您在 Visual 中看到的輸入存儲格式Studio 和 .Resx 文件,最終資源格式為二進制被編譯成 .NET 程序集的格式 (.Resources)編譯器.這些編譯的資源可以與二進制程序集中的代碼或資源衛(wèi)星中的代碼其唯一目的是提供資源的集會.通常在.NET 將 Invariant 文化資源嵌入到基礎中與存儲在衛(wèi)星組件中的任何其他培養(yǎng)物組裝在特定文化的子目錄中.
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 會自動編譯資源并將它們嵌入到程序集中并創(chuàng)建衛(wèi)星程序集以及每個所需的目錄結(jié)構(gòu)支持的語言環(huán)境.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 資源來提供服務本地化的內(nèi)容,因此這些工具似乎很自然框架提供了使資源創(chuàng)建工具可用于服務同樣的型號.
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 沒有提供一種簡單的方法來交叉引用資源跨多個地區(qū).盡管 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 資源也是靜態(tài)的– 它們畢竟被編譯成一個程序集.如果你想做對資源的更改需要重新編譯才能看到這些更改.ASP.NET 2.0 引入了可以存儲的全局和本地資源在服務器上并且可以動態(tài)更新 - ASP.NET 編譯器實際上可以在運行時編譯它們.但是,如果您使用預編譯的 Web 部署模型,資源最終仍然是靜態(tài)的,不能在運行時更改.所以一旦你完成了編譯資源是固定的.
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?
使用數(shù)據(jù)庫資源
這使我將資源存儲在數(shù)據(jù)庫.數(shù)據(jù)庫本質(zhì)上更具動態(tài)性,您可以使無需重新編譯數(shù)據(jù)庫即可更改數(shù)據(jù)庫中的數(shù)據(jù)應用.此外,數(shù)據(jù)庫數(shù)據(jù)更容易在之間共享多個開發(fā)人員和本地化人員,因此更容易進行更改團隊環(huán)境中的資源.
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.
當您考慮資源時編輯它基本上是一個數(shù)據(jù)輸入任務——你需要查找單個資源值,查看所有不同的語言變體然后添加和編輯每個不同語言環(huán)境的值.雖然所有這些都可以通過 Resx 文件中的 XML 來完成直接構(gòu)建數(shù)據(jù)庫的前端實際上要容易得多而不是散落在各處的 XML 文件.數(shù)據(jù)庫還為您提供更靈活地在不同視圖中顯示資源數(shù)據(jù)并且可以輕松執(zhí)行批量更新和重命名密鑰等操作和價值觀.
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 允許您創(chuàng)建自定義資源管理器(核心 .NET 運行時)和資源提供者(ASP.NET 2.0)從任何地方提供資源,包括一個數(shù)據(jù)庫.
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 數(shù)據(jù)庫 vs 提供本地化/全球化的自定義解決方案的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!