Saturday, July 5, 2008

Cultures in .NET Framework

The .NET Framework provides the CultureInfo class in System.Globalization namespace that allows manipulation and retrieval of information about the cultural context in which an application is running.

First of all, it is important to elaborate on the different culture categories available. The cultures in .NET can be grouped into three categories:

1. Invariant Culture
This culture category is culture-insensitive and is used as a default culture when consistency is desired.

2. Neutral Culture
A neutral culture is associated with a language but has no relationship to countries or regions. For example, the English spoken in UK is different from that spoken in the US. English (en), French (fr) and Spanish (sp) are examples of neutral cultures. This culture category will be designated by the first two characters in the CultureInfo class of .NET. If only the two letters are specified, they will be the Neutral class.

3. Specific Culture
This category is the most precise and is represented by a neutral culture, a hyphen, and then a specific culture abbreviation. For instance, in "fr-FR", fr is the neutral culture (French) and FR represents the specific culture (France).

CultureInfo in .NET Framework
The current culture information can be obtained via the CurrentCulture property of the executing thread's CurrentThread property.

CultureInfo cultureInfo = Thread.CurrentThread.CurrentCulture;









Enumerating all available cultures
To get hold of all the different cultures available, the following code can be used:

CultureInfo[] cultures = CultureInfo.GetCultures(CultureTypes.AllCultures);

The GetCultures() method accept the CultureTypes enum as an input parameter.



Windows XP Regional Options
Go to Control Panel --> Regional and Language Options --> Regional Options Tab



RegionInfo in .NET Framework
CultureInfo cultureInfo = Thread.CurrentThread.CurrentCulture;
RegionInfo regionInfo = new RegionInfo(cultureInfo.LCID);

No comments: