Introduction
Defining custom culture and region information is common practice in many enterprise environments.
In the .NET Framework 2.0, we can use the CultureAndRegionInfoBuilder class to build a custom culture that is new or based on an existing culture and region. The custom culture can be installed on a computer and subsequently used by any application running on that computer.
Using this class, I've built a small command line tool to extract, register and unregister culture and region information.
The Tool
The tool is just a simple command line parser that calls methods of the CultureAndRegionInfoBuilder class.
Extracting Culture and Region Information
For extracting culture and region information, an instance of CultureAndRegionInfoBuilder is created for the specified culture with the Replacement modifier and saved to the specified file.
private static void ExtractCultureAndRegionInfo(string cultureName, string filenName)
{
FileInfo fileInfo = GetFileInfo(filenName);
if (fileInfo.Exists)
{
fileInfo.Delete();
}
CultureAndRegionInfoBuilder cultureAndRegionInfoBuilder
= new CultureAndRegionInfoBuilder
(cultureName, CultureAndRegionModifiers.Replacement);
cultureAndRegionInfoBuilder.Save(fileInfo.FullName);
}
Registering Culture and Region Information
For registering culture and region information, an instance of CultureAndRegionInfoBuilder is created from the specified LDML definition file and registered.
private static void RegisterCustomCulture(string filenName)
{
FileInfo fileInfo = GetFileInfo(filenName);
CultureAndRegionInfoBuilder cultureAndRegionInfoBuilder =
CultureAndRegionInfoBuilder.CreateFromLdml(fileInfo.FullName);
cultureAndRegionInfoBuilder.Register();
}
Unregistering Culture and Region Information
For unregistering culture and region information, the Unregister
method of CultureAndRegionInfoBuilder is called for the specified culture.
private static void UnregisterCustomCulture(string cultureName)
{
CultureAndRegionInfoBuilder.Unregister(cultureName);
}