Share via


Dump the LDML for ALL the locales on the box

So, for whatever reason, you want to know what the LDML that the CultureAndRegionInfoBuilder needs is for all the locales for the box.  It's pretty trivial, but:

 

 using System;
using System.Globalization;

class DumpAllLocales
{
    static void Main()
    {
        foreach (CultureInfo culture in CultureInfo.GetCultures(CultureTypes.AllCultures))
        {
            try
            {
                // Skip invariant
                if (String.IsNullOrEmpty(culture.ToString())) continue;

                // Get the CARIB, watching out for neutrals & customs, and call save
                CultureAndRegionModifiers flags = culture.IsNeutralCulture ? CultureAndRegionModifiers.Neutral : CultureAndRegionModifiers.None;
                if ((culture.CultureTypes & CultureTypes.UserCustomCulture) != CultureTypes.UserCustomCulture)
                    flags |= CultureAndRegionModifiers.Replacement;
                CultureAndRegionInfoBuilder carib = new CultureAndRegionInfoBuilder(culture.ToString(), flags );
                // This will blow up if the file exists already
                carib.Save(culture.ToString() + ".ldml");
            }
            catch (Exception e)
            {
                Console.WriteLine("Error for culture " + culture.ToString());
                Console.WriteLine(e.Message);
            }
        }
    }
}
  
 put this in a .cs file, add .Net to your path, compile and run:
 
%windir%\Microsoft.NET\Framework\v4.0.30319 /r:sysglobl.dll dumpAllCultures.cs
 dumpAllCultures.exe
 
 -Shawn