問題描述
我們使用 resx 文件來本地化我們的 Web 應用程序.當只有一個頁面使用某個短語時,我們通常會創建本地 resx 文件(映射到特定頁面),而當多個頁面需要該短語時,我們會創建全局 resx 文件.
但是全局 resx 文件的好處是它們是一個類,你可以像調用類的屬性一樣調用短語:
We use resx files to localize our web applications. We usually create local resx files (that map to a specific page) when only one page uses a certain phrase, and a global resx file when more than one page needs the phrase.
But the good thing about global resx files is that they are a class, and you can call the phrases like you call properties of a class:
Resource.UI.iNotFound
Resource.UI.iNotFound
所以我在想 - 為什么要有本地 resx 文件?為什么不對整個應用程序使用一個全局 resx 文件,這樣可以避免調用不存在的短語導致運行時錯誤?
So I was thinking - why have local resx files at all? why not use one global resx file for the whole application, and that way avoid runtime errors from calling non-existent phrases?
我確定有一個很好的答案,我只是不知道它是什么......
I'm sure there's a good answer for that, I just don't know what it is....
推薦答案
我一直在尋找指南,并在 MSDN:
I kept on looking for guidelines, and found this in MSDN:
在全局和本地資源文件之間進行選擇
您可以使用全局的任意組合和 Web 中的本地資源文件應用.通常,您添加資源到全局資源文件當你想分享資源時頁面之間.全球資源資源文件也是強類型的當您想要訪問文件時以編程方式.
You can use any combination of global and local resource files in the Web application. Generally, you add resources to a global resource file when you want to share the resources between pages. Resources in global resource files are also strongly typed for when you want to access the files programmatically.
但是,全局資源文件可以變大,如果你存儲所有其中的本地化資源.全球的資源文件也可以更多難以管理,如果不止一個開發人員正在研究不同的頁面但在單個資源文件中.
However, global resource files can become large, if you store all localized resources in them. Global resource files can also be more difficult to manage, if more than one developer is working on different pages but in a single resource file.
本地資源文件更容易管理單個 ASP.NET 的資源網頁.但你不能分享頁面之間的資源.此外,你可能會創建很多本地的資源文件,如果你有很多頁面必須本地化為許多語言.如果網站很大許多文件夾和語言,本地資源可以快速擴展中的組件數應用領域.
Local resource files make it easier to manage resources for a single ASP.NET Web page. But you cannot share resources between pages. Additionally, you might create lots of local resource files, if you have many pages that must be localized into many languages. If sites are large with many folders and languages, local resources can quickly expand the number of assemblies in the application domain.
當您更改默認資源文件時,本地或全局,ASP.NET重新編譯資源并重新啟動ASP.NET 應用程序.這個可以影響你的整體表現地點.如果添加衛星資源文件,它不會導致重新編譯資源,但ASP.NET 應用程序將重新啟動.
When you make a change to a default resource file, either local or global, ASP.NET recompiles the resources and restarts the ASP.NET application. This can affect the overall performance of your site. If you add satellite resource files, it does not cause a recompilation of resources, but the ASP.NET application will restart.
所以看來編程團隊需要權衡每種方法的優缺點,然后選擇對他們有利的方法.
So it seems that it's really up to the programming team to weigh the pros and cons of each method and choose what's good for them.
這篇關于ASP.NET 中的全局資源與本地資源的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!