简体   繁体   English

多个资源文件与单个资源文件

[英]multiple resource files versus single resource file

This question is about the performance 这个问题与性能有关

I am working on MVC4 and I want to support multi-language views. 我正在研究MVC4,我想支持多语言视图。

I am using one resourse file for each language like this: 我正在为每种语言使用一个resourse文件,如下所示:

Multi.resx For English as default
Multi.ar.resx for Arabic 
Multi.fr.resx for Frensh

and after specifying the culture, I do this in my views 在指定文化之后,我在我的观点中这样做

@Multi.Name

However, I make breakpoints to check the value of @Multi and really it contains all the keys in my resources. 但是,我创建了断点来检查@Multi的值,它实际上包含了我资源中的所有键。 Imagine all of them :P 想象一下所有人:P

My question is: would it perform better if I used a resource file for each view? 我的问题是:如果我为每个视图使用资源文件,它会表现得更好吗? Or will all the resources be loaded when I run my application even if I use multiple resource files for each view? 或者,即使我为每个视图使用多个资源文件,在运行我的应用程序时是否会加载所有资源?

I am really not good at english, if you didn't understand my question, just ask me to clarify. 我真的不擅长英语,如果你不理解我的问题,请让我澄清一下。

I know this is old thread, but I am also looking for the answer. 我知道这是旧线程,但我也在寻找答案。 Was single (and huge resource) file will effect the performance? 单个(和巨大的资源)文件会影响性能吗? .

After researching, I found this link and I thought to share with you (in case you are still looking). 经过研究,我找到了这个链接 ,我想与你分享(如果你还在寻找)。

Well, the short answer is NO , it will NOT affect the performance. 嗯,简短的答案是否定的 ,它不会影响性能。 However, it may cause problem when working in large team (where each of the programmer requires to modify the same resource file) and it can be troublesome to merge the changes. 但是,在大型团队中工作时可能会出现问题(每个程序员都需要修改相同的资源文件),并且合并更改会很麻烦。

Here is the guideline from MSDN : 以下是MSDN的指南:

Choosing Between Global and Local Resource Files 在全局和本地资源文件之间进行选择

You can use any combination of global and local resource files in the Web application. 您可以在Web应用程序中使用全局和本地资源文件的任意组合。 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. 如果多个开发人员在不同的页面上工作但在单个资源文件中,则全局资源文件也可能更难管理。

Local resource files make it easier to manage resources for a single ASP.NET Web page. 本地资源文件使管理单个ASP.NET网页的资源变得更加容易。 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. 如果站点很大且包含许多文件夹和语言,则本地资源可以快速扩展应用程序域中的程序集数量。

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. 当您对默认资源文件(本地或全局)进行更改时,ASP.NET会重新编译资源并重新启动ASP.NET应用程序。 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. 如果添加卫星资源文件,则不会导致重新编译资源,但ASP.NET应用程序将重新启动。

I hope this can help someone who seeking the same answer. 我希望这可以帮助那些寻求相同答案的人。

Cheers, Sam 干杯,山姆

此问题(实际回答)中描述了您的问题的解决方案:将大型资源文件物理拆分为多个文件,而编译器将其视为一个

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM