环球资源与ASP.NET中的本地资源 [英] Global resource vs. Local resource in ASP.NET

查看:98
本文介绍了环球资源与ASP.NET中的本地资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们使用的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中的本地资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆