Creating Custom Cultures


.NET 2.0 has a new feature to create custom cultures. Custom cultures can be created for cultures that are not available with the .NET Framework. Some examples of where creating custom cultures can be useful are to support a minority within a region or to create subcultures for different dialects.

Custom cultures and regions can be created with the class CultureAndRegionInfoBuilder in the namespace System.Globalization. This class is in the assembly sysglobl in the file sysglobl.dll.

In the example, a new culture for a region inside Austira is defined: Styria. The new culture is based on the culture de-AT and on the region AT. With the constructor of the class CultureAndRegionInfo Builder, the name of the new culture is set to de-AT-ST. With the last argument of the constructor a prefix can also be assigned with the enumeration CulturePrefix. Here, no prefix is used, and the enumeration value CulturePrefix.None is passed. After the name of the new culture is defined, the default settings for the culture are loaded. The method LoadDataFromCulture() loads all the culture settings for the specified culture de-AT, and the method LoadDataFromRegion() loads all the region settings for the specified region AT.

After the CultureAndRegionInfoBuilder object is instantiated, it is possible to change some cultural behavior of the new culture by setting properties. Calling the method Register() registers the new culture with the operating system. Indeed, you can find the file that describes the culture in the directory<windows>\Globalization. Look for files with the extension nlp.

 // Create a Styria culture CultureAndRegionInfoBuilder styria = new CultureAndRegionInfoBuilder( "de-AT-ST", CultureAndRegionModifiers.None); styria.LoadDataFromCulture(new CultureInfo("de-AT")); styria.LoadDataFromRegion(new RegionInfo("AT")); styria.Register(); 

The newly created culture now can be used like other cultures:

 CultureInfo ci = new CultureInfo("de-AT-ST"); Thread.CurrentThread.CurrentCulture = ci; Thread.CurrentThread.CurrentUICulture = ci; 




Professional C# 2005
Pro Visual C++ 2005 for C# Developers
ISBN: 1590596080
EAN: 2147483647
Year: 2005
Pages: 351
Authors: Dean C. Wills

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net