6.8.08

Globalization and Localization in ASP.NET

  • What is Globalization and Localization in ASP.NET?

Answer - Localization is the process of adapting a software application for a specific locale. Globalization is the process of identifying the localizable resources of the application. You can provide support for Localization and Globalization to the application using System.Globalization, System.Resources and System.Threading namespaces.

The developer can define culture specific information using the System.Globalization namespace. The System.Resources namespace contains ResourceManager class that allows access to resources either from the main assembly or from the Satellite Assemblies. The System.Threading namespace supports for multithreaded programming.

A web form has two culture values, Culture and UICulture. Culture value is used for date and number formatting and UICulture values are used to determine culture specific resources.

You can set culture and UICulture values in the application as follows.

Using element of Web.Config.

Using @Page directive in the Page.

In Code-Behind Page

e.g.Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture ("en-GB");

Thread.CurrentThread.CurrentUICulture=new CultureInfo("en-GB");

  • What are the Globalization approaches possible in ASP.NET?

Answer - You can follow many approaches to have globalized application.

You can create separate web application for each culture.

You can create an application that can detect the user’s culture and adjusts output at run time using format specifiers and other tools.

You can store culture-dependent strings in resource files that are compiled into satellite assemblies.

  • Implementing ASP.NET Globalization

Answer - Create resource files and compile them into a binary resource file.

Create satellite assembly for each of the resource file for each culture.

Store them in separate folders for easy access and replacement.

Read the resources from the satellite assembly that is stored in different folders based on the locale and culture.

  • Define Resource Files and Satellite Assemblies

Answer-Resource Files: A resource file contains non-executable data that are used by the application and deployed along with it. Bitmaps, Icons etc are the examples of resource files. In ASP.NET, resource files are used to make application to support multiple cultures. You can create resource files each of them correspond to specific locale or culture of the application. You can use resgen utility to compile resource file into an assembly. You can create a satellite assembly from a compiled resource file using the AL utility provided with Microsoft .NET SDK

Advantages of resource files are as follows.

It supports Globalization features in ASP.NET.

You can have culture based information separate from the content and logic of the application.

You can change resource content without effecting application's code.

Satellite Assemblies

Satellite Assemblies are the special kinds of assemblies that exist as DLL and contain culture-specific resources in a binary format. They store compiled localized application resources. They can be created using the AL utility and can be deployed even after deployment of the application. Satellite Assemblies encapsulate resources into binary format and thus make resources lighter and consume lesser space on the disk.

Note: Resource-only assemblies can contain any resource, such as images and text. Satellite assemblies contain only culture-specific resources

No comments: