About BhashaIndia | Contribute | SiteMap | Register | Sign in to Windows Live ID
  Developers Patrons
Hindi Tamil Kannada Gujarati Marathi Telugu Bengali Malayalam Punjabi Konkani Oriya Sanskrit Nepali
Home > Developers > Tutorial > dotnet > ASP.NET 2.0 Welcome Guest!

ASP.NET 2.0 Localization Features

By Aparna Ravindran

Most Web applications that are created cater to the customer requirements all over the world. Because of the diverse cultures that exist, it is necessary to create Web applications that enable access to users in different locales. Localization of Web sites in the previous versions of ASP.NET is handled with the help of the ResourceManager class. It also used satellite assemblies and other culture-aware classes for localizing a Web site. However, the limitation is that ASP.NET does not provide you with tools to integrate the use of the ResourceManager class, satellite assemblies and other culture-aware classes into the Web forms programming model.
Microsoft has released ASP.NET 2.0 version with enhancements in the areas of tools, runtime capabilities and API’s for programming the localization features. These enhancements aim at providing:
    • Tools to extract localizable content from web pages.
    • More integrated runtime support for resource consumption.
    • Declarative constructs for binding resources to page output.
The features provided by ASP.NET 2.0 to put forth the above enhancements are:
    • Automatic Resource Generation
    • Managed Resource Editor
    • Declarative Localization Expressions
    • Strongly-Typed Resources
Automatic Resource Generation
ASP.NET 2.0 provides you an easy method to generate the resources automatically. To generate a local resource for a particular Web form, select Generate Local Resource sub-menu from the Tools menu of VS.NET 2005. The local resources should be created in the Design View of the Web form. When you attempt to create a local resource from the Source View of the Web form, an error will be thrown and you will be directed to move to the Design View of the Web form. The local resources can also be created for User Controls and Master Pages in their respective Design Views.
When a you create local resource, a .resx file will be automatically created. This file will be placed under the LocalResources sub-directory (automatically created by VS.NET) of the application’s root directory. You can view the created sub-directory in the Solution Explorer of the VS.NET 2005. The name of the created .resx file will be preceded by the name of the Web form. For example, if the name of the Web form is Login.aspx then the respective resource file will be named as Login.aspx.resx. Therefore, each Web form can contain a .resx file identified by the name of the Web form. All the .resx files created for multiple Wforms will be stored in the LocalResources sub-directory.
Managed Resource Editor
Generating the resource automatically can lead to a problem of duplication. Because each Web form owns it own .resx file, some data in the .resx files may be repeated. To overcome this duplication problem, you can create shared resources. These resource files will be placed under the Resources sub-directory (automatically created by VS.NET) of the application’s root directory.
A shared resource file is created manually by creating a new Assembly Resource file (.resx) from the Add New Item sub-menu of the Website menu. This file will be added to the application. The .Net Framework creates a new empty .resx file under the Resources sub-directory whose contents have to be filled manually. These files can be edited using the Managed Resource Editor provided by the VS.NET 2005.
The Managed Resource Editor defines a set of pre-defined categories namely Strings, Icons, Audio, Images, Files and Other file categories such as text and XML files. Any files of these pre-defined types can be added and can be used by all the Web forms in a Web application.
Local and shared resources created can be accessed programmatically or declaratively to generate the localized content.
Declarative Localization Expressions
This feature is specifically defined for accessing of resource information. The declarative expressions are categorized into two types namely, implicit and explicit expressions. Implicit expressions are expressions that are automatically generated when a control is added to a Web form containing a local resource. Explicit expressions are those specified by you to add additional content to the resource files that needs to be localized.
When a local resource is created for the Web form, the resource file will contain the information regarding all the controls available in the Web form along with some properties of those controls. For example, a Label control named label1 is added to the Web form and its text property is set to “Hi”. When the HTML code is generated for this Label control, it will contain a resourcekey property specifying that the Web form contains a local resource as shown below:
<asp:Label ID="Label1" Runat="server" Text="Hi" Width="54px" Height="17px" meta:resourcekey="LabelResource1"></asp:Label>
The value of the meta:resourcekey property defines the prefix for all the resource entries with respect to specific properties of the control. This is termed as Implicit expression.
Explicit expressions provide a method to declaratively assign specific resource entries to the properties of the server control, HTML elements and other static text. The syntax for creating explicit expression is shown below:
<%$ Resources applicationkey, resourcekey, default %>
where, applicationkey (optional) specifies the application name from where the resource information needs to be read; resourcekey specifies the local resource name of the control; default (optional) specifies the designer’s default value for the control.
The following example shows how to create explicit expressions:
<asp:TextBox ID="TextBox1" Text="<% $ resources: LabelResource1.Text%>" Runat="server"></asp:TextBox>
In the above line of code, the text property of the TextBox is set by reading the local resource information.
Strongly Typed Resources
You can access the entries in the resource file of an application with the help of their resource keys. To enable this, your resource should be a strongly typed resource. They provide the ability to create classes containing read-only properties for resources. Strongly typed resource can be created by compiling the shared resources. After compiling, the intellisense feature allows you to access the resources through the intrinsic Resources object.
Thus, the localization features of ASP.NET 2.0 provides you the method to read the resource file information and make it available to the Web forms without the use of the ResourceManager class.

Partner Profile | Privacy Statement | Why Passport | Testimonials
This site uses Unicode for non-English characters and uses Open Type fonts.
©2003-2007 Microsoft Corporation. All rights reserved.