Click here to Skip to main content
Licence CPOL
First Posted 24 Jan 2007
Views 23,333
Downloads 131
Bookmarked 18 times

Culture and Region Information Tool for .NET 2.0

By | 29 Jan 2007 | Article
A Culture and Region Information tool for .NET 2.0 based on System.Globalization.CultureAndRegionInfoBuilder

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);
}

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Paulo Morgado

Software Developer (Senior)
Paulo Morgado
Portugal Portugal

Member

About Paulo Morgado

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
QuestionHelp PinmemberMarkRedman5:30 29 Jan '07  
AnswerRe: Help PinmemberM.Lansdaal10:14 29 Jan '07  
There is an excellent book on the topic of .NET Internationalization, whose author has posted a couple of sample chapters on his web site at http://www.dotneti18n.com/SampleChapter.aspx. The second sample chapter (Chapter 11 - Custom Cultures[^]) will answer pretty much all your questions (it did for me).
 
Thanks, Mike Lansdaal
AnswerRe: Help PinmemberPaulo Morgado11:59 29 Jan '07  
AnswerRe: Help PinmemberMarkRedman12:47 29 Jan '07  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web03 | 2.5.120529.1 | Last Updated 29 Jan 2007
Article Copyright 2007 by Paulo Morgado
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid