|
This article is based on .Net 2.0 / ASP.Net 2.0
Down Load this Project
A satellite assembly is defined as an assembly with resources only, no executable code.
A .NET Framework assembly contains resources specific to a given language. Using satellite assemblies, you can place the resources for different languages in different assemblies, and the correct assembly is loaded into memory only if the user elects to view the application in that language.
This means that you develop your application in a default language and add flexibility to react with change in the locale. Say, for example, you developed your application in an en-US locale. Now, your application has multilingual support. When you deploy your code in, say, China, you want to show labels, messages shown in the national language which is other than English.
Resource Files
A resource file is an XML file that contains the strings that you want to translate into different languages or paths to images. The resource file contains key/value pairs. Each pair is an individual resource. Key names are not case sensitive. For example, a resource file might contain a resource with the Button1 key and the Submit value.
You create a separate resource file for each language (for example, English and French) or for a language and culture (for example English [U.K.], English [U.S.]). Each localized resource file has the same key/value pairs; the only difference is that a localized resource file can contain fewer resources than the default resource file. Language fallback then handles loading the neutral or default resource.
Resource files in ASP.NET have an .resx extension. At run time, the .resx file is compiled into an assembly, which is sometimes referred to as a satellite assembly. Because the .resx files are compiled dynamically, in the same manner as ASP.NET Web pages, you do not have to create the resource assemblies. The compilation condenses several similar-language resource files into the same assembly.
|
|
When you create resource files, start by creating a base .resx file. For each language that you want to support, create a new file that has the same basic file name, but with a language or language and culture (culture name) as part of it. For a list of culture names, see CultureInfo.
Creating Resource Files for ASP.NET Web Sites
In ASP.NET, you can create resource files that have different scope. You can create resource files that are global, which means that you can read the resource file from any page or code that is in the Web site. You can also create local resource files, which store resources for a single ASP.NET Web page (.aspx file).
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, which gives developers 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 (an ASP.NET page with the extension of .aspx, .ascx, .master, and so on). You put local resource files in folders that have the reserved name App_LocalResources. App_LocalResources folders can exist in any folder in the application, unlike the root App_GlobalResources folder. You associate a set of resources files to a specific Web page using the name of the resource file.
Choosing Between Global and Local Resource Files
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, using 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, which can affect the overall performance of your site. Adding satellite resource files will not cause a recompilation of resources, but the ASP.NET application will restart.
The CLR and the base class library of the .NET Framework come with several classes for managing and accessing resources in applications. These classes are located in the System.Resources and System.Globalization namespaces. Here we will explore the necessary details for working with resources in ASP.NET applications and for creating international ASP.NET applications based on embedded resources and the integrated localization support.
Next Page
|