Whidbey .Net 2.0 Custom Culture Example (Beta 2)

Here’s an example of how to create a custom culture in Whidbey.  Its changed a bit from earlier versions, so this code is based on Beta 2 behavior.  This should be what you see in RTM. J


This sample creates a custom culture with the name “en-US-shawn”, changes a couple things and then uses that culture to display that we did indeed get custom behavior.  It then unregisters it.  Copy the example to something like cultures.cs and then use

            csc /r:sysglobl.dll cultures.cs



Output is something like:

Data from our new culture:


Shawn's version of en-US

3/8/2005 17:33:50 PM (shawn)


Data from our new culture's parent:


English ( United States)

3/8/2005 5:33 PM


This WILL NOT compile on previous prerelease versions, so be patient J  I had questions though so wanted people to be able to see how the custom culture mechanism worked.  If for some reason this culture doesn’t unregister, delete the %windir%globalizationen-us-shawn.nlp file by hand.


// This posting is provided "AS IS" with no warranties, and confers no rights. Use of included samples are subject to the terms specified at http://www.microsoft.com/ info/cpyright.htm

using System;

using System.Globalization;


// Example of creating a custom culture.

namespace cultures


    public class mycultures


        static void Main(string[] args)


            // First we need a CultureAndRegionInfoBuilder


            // Base it on en-US, add my name

            CultureAndRegionInfoBuilder carib = new CultureAndRegionInfoBuilder(

                "en-US-shawn", CultureAndRegionModifiers.None);


            // Our parent is en-US, load those defaults

            CultureInfo enUS = new CultureInfo("en-US");


            carib.LoadDataFromRegionInfo(new RegionInfo("en-US"));



            // Override a few things so we know we changed it

            carib.CultureEnglishName = carib.CultureNativeName = "Shawn's version of en-US";


            // Date time is a little more challenging to override.

            DateTimeFormatInfo dtfi = new CultureInfo("en-US").DateTimeFormat;

            dtfi.ShortTimePattern = "HH:mm:ss tt' (shawn)'";

            carib.GregorianDateTimeFormat = dtfi;


            // Register it



            // Now try to use it

            Console.WriteLine("Data from our new culture:");

            CultureInfo enUsShawn = new CultureInfo("en-US-shawn");



            Console.WriteLine(DateTime.Now.ToString("g", enUsShawn));



            // Compare that to our parent

            Console.WriteLine("Data from our new culture's parent:");

            enUS = enUsShawn.Parent;



            Console.WriteLine(DateTime.Now.ToString("g", enUS));


            // Now we're done with it





Comments (5)

  1. Whidbey .Net 2.0 Custom Culture Example

  2. a. says:



    well, looks a bit… ugly.

  3. Shawn Steele says:

    Fortunately you only have to use the CultureAndRegionInfoBuilder once to get it onto a machine, so hopefully any "ugliness" doesn’t have to be used often 🙂

  4. zoli says:

    Thank’s for the sample app. That’s missing from the MSDN 😉

  5. I should mention (now) that I’d really prefer people to use the Microsoft Locale Builder tool if at all possible 🙂  I think of locales kind of like fonts: if you want one you use a tool to build it and then install that on the machine.  

Skip to main content