Thursday, May 24, 2012

What is Local Resource File and Global Resource File?


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.

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.

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.

Global Resource Files

You create a global resource file by putting it in the reserved folder App_GlobalResources at the root of the application. Any .resx file that is in the App_GlobalResources folder has global scope. Additionally, ASP.NET generates a strongly typed object that gives you a simple way to programmatically access global resources.

Local Resource Files

A local resources file is one that applies to only one ASP.NET page or user control (an ASP.NET file that has a file-name extension of .aspx, .ascx, or .master). You put local resource files in folders that have the reserved name App_LocalResources. Unlike the root App_GlobalResources folder, App_LocalResources folders can be in any folder in the application. You associate a set of resources files with a specific Web page by using the name of the resource file.

For example, if you have a page named Default.aspx in the App_LocalResources folder, you might create the following files:

Default.aspx.resx. This is the default local resource file (the fallback resource file) if no language match is found.

Default.aspx.es.resx. This is the resource file for Spanish, without culture information.

Default.aspx.es-mx.resx. This is the resource file for Spanish (Mexico) specifically.

Default.aspx.fr.resx. This is the resource file for French, without culture information.

The base name of the file matches the page file name, followed by a language and culture name, and ending with the extension .resx. For a list of culture names, see CultureInfo.


To use implicit localization

Open the page for which you want to create resource files.

Switch to Design View.

In the Tools menu, click Generate Local Resource.

Visual Web Developer creates the App_LocalResources folder if it does not already exist. Visual Web Developer then creates the base resource file for the current page, which includes a key/name pair for every localizable control of every ASP.NET Web server control on the page. Finally, Visual Web Developer adds a meta attribute to each ASP.NET Web server control to configure the control to use implicit localization.

0 comments:

Post a Comment