Jaa


Dumping Custom Culture LDML for all built-in files

Sometimes you want to see what's in a built-in culture, or maybe you want to figure out what data's in an uplevel culture so that you can make a similar custom culture for an older OS.  Here's an easy way to dump the LDML files for all of the cultures on the system, copy this to some .cs file and then build:

using System;
using System.Globalization;

class DumpCaribs
{
    static void Main()
    {
        foreach (var culture in CultureInfo.GetCultures(CultureTypes.AllCultures))
        {
            if (culture.Name != "")
            {
                try
                {
                    var flags = CultureAndRegionModifiers.Replacement;
                    if (culture.LCID == 0x1000 || culture.LCID == 0x0c00) flags = CultureAndRegionModifiers.None;
                    if (culture.IsNeutralCulture) flags |= CultureAndRegionModifiers.Neutral;
                    CultureAndRegionInfoBuilder carib = new CultureAndRegionInfoBuilder(
                        culture.Name, flags);
                    Console.WriteLine("Creating " + culture.Name);
                    carib.Save(culture.Name + ".ldml");
                }
                catch
                {
                    Console.WriteLine("Difficulty dumping " + culture.Name);
                }
            }
        }
    }
}

Remember to compile with the /r:sysglobl.dll flag for the CultureAndRegionInfoBuilder.  So if you put the above code in a file named carib.cs, use this to compile:

csc carib.cs /r:sysglobl.dll

Use the latest version of .Net to make sure you pick up any of the newer properties.