Globalization and Localization

Globalization and Localization

Globalization and localization are two different but related processes. Globalization involves applying culture-based formatting to existing data, and localization involves retrieving the appropriate piece of data based on the culture. The following examples illustrate these differences:


Currency is formatted in some countries using a period (.) as a thousand separator and a comma as a decimal separator. A globalized application will take the existing data for currency and format it appropriately based on location.
Localization. The title of a form might be displayed in English or French depending on the country in which it is deployed.

A localized application will retrieve the appropriate string, in English or French, and display it according to the location.


In your application, culture refers to the cultural information about the region in which the application is being used. In the .NET Framework, cultures are identified using a culture code. The culture code is a code that represents to the framework what the current language is.

A culture code can also specify information about the region in which an application is being used. Generally, the culture code is either a two letter code that only specifies the language that is spoken or a two letter language code followed by a dash and another two letter code that specifies the region. Culture codes that only specify the language are called neutral cultures, whereas cultures that specify the language and the region are called specific cultures.

Getting and Setting the Current Culture

The application automatically reads the system culture settings and implements them. You can change the current culture of your application programmatically by setting the current culture to a new instance of the CultureInfo class.

This class holds all of the information about a culture and how it should interact with your application. For example, the CultureInfo class contains information on which calendar is used, which type of currency formatting is used, which type of date formatting is used, and so on. You can set the culture of an application programmatically by setting the CurrentThread.CurrentCulture property to a new instance of the CultureInfo class.

Implementing Localization

Localization allows you to provide a different representation of the user interface based on culture. The .NET Framework makes it easy for you to create localized forms by creating resource files that hold data for alternative versions of forms for each culture your application supports. At run time, the appropriate version of the form is loaded based on the CultureInfo.CurrentUICulture property.

Getting and Setting the Current UI Culture

The UI culture is also represented by an instance of CultureInfo as the CultureInfo.CurrentUICulture property and is distinct from the CultureInfo.CurrentCulture property.

The CurrentCulture setting determines the kinds of formatting that will be applied to formatted data, whereas the CurrentUICulture determines the resources that will be loaded at run time for localized forms. You can retrieve the CurrentUICulture by accessing the CultureInfo.CurrentUICulture property.

Creating Localized Forms

Creating localized forms with the .NET Framework is a nearly effortless process. Every form exposes a Localizable property that determines if the form is localized or not. Setting this property to true enables localization.

When the Localizable property of a form is set to true, Visual Studio .NET automatically handles the creation of appropriate resource files. This is handled through the Language property of the form. When this property is set to (Default), you can edit any of the UI properties of the form or controls to provide a representation for the default UI culture.

To create a localized version of the form, you can set the Language property to any value other than (Default). Visual Studio .NET will automatically create a new resource file for the new language and store any values you set for the UI in that new resource file.

To create localized forms

Set the Localizable property of your form to true.

Design the user interface of your form and translate any UI elements into the localized languages.

Add UI elements for the default culture. This is the culture that will be used if no other culture is specified.

Set the Language property of your form to the appropriate culture.

Add the localized UI content to your form.

Repeat Steps 4 and 5 for each localized language.

Build your application.

When the CurrentUICulture is set to a localized culture, your application will load the appropriate version of the form by reading the corresponding resource files. If no resource files exist for a specified culture, the default culture UI will be displayed.

Validating International Input

You might need to incorporate techniques for validating international input into your application. Validating keystroke input can be particularly problematic for international applications. The developer might be unfamiliar with the character system used in a particular locale and be unable to determine what category keystrokes belonged to.

You can use the validation methods provided in the Char structure to make these determinations in much the same way as you would for Latin alphabet input. The Char.IsDigit, Char.IsLetter, and other methods will return appropriate values no matter what input character set is used. Thus, validation code that uses these methods will function correctly without any special modification.

Culture-Specific Formatting

You can supply your own values for specific members of CultureInfo to tailor your application to your specific cultural needs. For example, suppose you are writing an application for a client that collaborates with a group in Japan, but the currency used in the application is US dollars. You would need to create an application that uses Japan-specific formatting for most elements, but always uses the dollar sign ($) as the currency symbol.

Implementing Right-to-Left Display

Some languages are read from right-to-left instead of left-to-right as is used in most Latin alphabet languages. Standard Windows Forms provide a RightToLeft property that enables implementation of a right-to-left user interface in your application.

The RightToLeft property has three settings: Yes, No, and Inherit, with Inherit being the default value. When this property is set to Inherit, the RightToLeft value is determined by the value of the parent control.

Setting a control's RightToLeft property to Yes does several things, depending on the type of control. Text alignment is reversed. Thus, any text that was normally left-aligned in the control becomes right-aligned. If a form's RightToLeft property is set to Yes, its caption is right-aligned.

Vertical scroll bars are displayed on the left side, and horizontal scroll bars are initialized with the slider right- aligned. Check boxes have their CheckAlign property reversed.

Tab buttons are reversed and the alignment of items in list boxes and combo boxes is reversed. In short, each control becomes a mirror of itself with respect to formatting.

Converting Character Encodings

The .NET Framework uses Unicode UTF-16 character encoding to represent characters. The Unicode character set has become a universal standard for representing characters. Each of over 65,000 characters has a unique representation in this character set, and there is room for the Unicode character set to expand by over a million more characters. Thus, it is ideal for representing international text content.

Before Unicode, however, the language requirements for different cultures forced developers to use diverse encodings to represent data internally. Thus, data from different cultures came to be represented in different character sets, such as Single-Byte editions for European languages, Double-Byte editions for Asian languages, and Bidirectional editions for Middle Eastern languages.

This fragmentation has made it difficult to share data between cultures and even more difficult to develop world-ready applications that support a multilingual user interface.

The .NET Framework allows you to convert legacy data in other formats to Unicode data. Also, if interaction with legacy components is required, you can convert Unicode data into the legacy-encoding format.

Encoding conversions are carried out by the Encoding class, which is found in the System.Text namespace. The Encoding class cannot be directly instantiated, but you can obtain an instance of this class by using the Shared (static) method, Encoding.GetEncoding, to get an encoding that specifies a particular character code page.












No comments:

Post a Comment