Creating a Custom Culture (Locale) From Microsoft-ish LDML


[Updated 11 Aug 2006 to reflect IETF style locale names]

This is just a simple example of creating a custom culture from an LDML file.  The LDML file has to have Microsoft specific tags otherwise you will get some errors for the missing data.  The resulting custom culture/locale works in .Net Framework 2.0 (new CultureInfo(“tlh-Latn-US”)) and Windows Vista.  Custom locales are a new Windows Vista feature, so this won’t work on XP or other Windows machines.

To try this with the .Net Framework 2.0 or a Windows Vista machine (which has .Net 2.0 installed), copy the following to a .cs file (like culture.cs)

using System;
using System.Globalization;

namespace Example
{
    class CultureLdml
   
{
       
static void Main(string[] args)
       
{
           
CultureAndRegionInfoBuilder carib = CultureAndRegionInfoBuilder.CreateFromLdml(“tlh-Latn-US.ldml”);
           
carib.Register();
        }
   
}
}

Copy the ldml file from http://blogs.msdn.com/shawnste/archive/2005/11/23/496426.aspx to the same directory, compile it and run it.  The tlh-Latn-US locale/culture should now be available for your use!  If you need specific steps, do this:

1.  Open a command window (Start->Run and type cmd)
2.  Type “notepad culture.cs” and copy the above code to the file, save it & close notepad
3.  Type “notepad tlh-Latn-US.ldml” and copy the XML from http://blogs.msdn.com/shawnste/archive/2005/11/23/496426.aspx to that file, save it in the same place & close notepad.
4.  Make sure csc is in your path.  Type “path=%path%;%windir%Microsoft.NETFrameworkv2.0.50727” and press enter (don’t type the quotes.)
5.  Type “csc /r:sysglobl.dll culture.cs” to compile the short program.
6.  Type “culture.exe” to run the program.
7.   “dir %windir%globalization” should reveal a new tlh-Latn-US.nlp file with the custom culture on it.

In Windows Vista you could now set this locale to your user locale.  Type “intl.cpl” to open the Regional and Language Options control panel.  You should be able to select “Klingon (United States)” from the locale list, then hit Apply and look at the times in your clock 🙂

I blogged about why I chose Klingon (a fictitious language, see http://www.kli.org/ for info) and why I did what I did in my culture in this post.  I’ll also use this example to blog about the LDML file and how the Microsoft specific tags work, so stay tuned.  I’ll update this paragraph when I have links.

This is just a simple example of creating a custom culture from an LDML file.  The LDML file has to have Microsoft specific tags otherwise you will get some errors for the missing data.  The resulting custom culture/locale works in .Net Framework 2.0 (new CultureInfo(“tlh-Latn-US”)) and Windows Vista.  Custom locales are a new Windows Vista feature, so this won’t work on XP or other Windows machines.

To try this with the .Net Framework 2.0 or a Windows Vista machine (which has .Net 2.0 installed), copy the following to a .cs file (like culture.cs)

using System;
using System.Globalization;

namespace Example
{
    class CultureLdml
   
{
       
static void Main(string[] args)
       
{
           
CultureAndRegionInfoBuilder carib = CultureAndRegionInfoBuilder.CreateFromLdml(“tlh-Latn-US.ldml”);
           
carib.Register();
        }
   
}
}

Copy the ldml file from http://blogs.msdn.com/shawnste/archive/2005/11/23/496426.aspx to the same directory, compile it and run it.  The tlh-Latn-US locale/culture should now be available for your use!  If you need specific steps, do this:

1.  Open a command window (Start->Run and type cmd)
2.  Type “notepad culture.cs” and copy the above code to the file, save it & close notepad
3.  Type “notepad tlh-Latn-US.ldml” and copy the XML from http://blogs.msdn.com/shawnste/archive/2005/11/23/496426.aspx to that file, save it in the same place & close notepad.
4.  Make sure csc is in your path.  Type “path=%path%;%windir%Microsoft.NETFrameworkv2.0.50727” and press enter (don’t type the quotes.)
5.  Type “csc /r:sysglobl.dll culture.cs” to compile the short program.
6.  Type “culture.exe” to run the program.
7.   “dir %windir%globalization” should reveal a new tlh-Latn-US.nlp file with the custom culture on it.

In Windows Vista you could now set this locale to your user locale.  Type “intl.cpl” to open the Regional and Language Options control panel.  You should be able to select “Klingon (United States)” from the locale list, then hit Apply and look at the times in your clock 🙂

I blogged about why I chose Klingon (a fictitious language, see http://www.kli.org/ for info) and why I did what I did in my culture in this post.  I’ll also use this example to blog about the LDML file and how the Microsoft specific tags work, so stay tuned.  I’ll update this paragraph when I have links.


Comments (5)

  1. ivpet says:

    Hi Shawn.

    Is it possible to use this *.nlp files in Windows XP?

    I created one, but I can’t find the created Culture in Regional and Language Options???

    Regards,

    Ivan Petrov.

  2. Shawn Steele says:

    Sorry, custom locales are a Windows Vista feature, you’ll need to install the Vista Beta. Its available to MSDN subscribers.

    See http://windowssdk.msdn.microsoft.com/library/default.asp?url=/library/en-us/intl/nls_CustLocaleSuppleAndReplace.asp for more info.

  3. Use custom keyboards, locales, fonts and font linking to create a solution for complex custom locales.  I use the made-up Klingon language and pIqad script for my example.

  4. Dan Anos says:

    Hi,

     I think you can also install ldml files on Windows 2003. I remember installing the EN-IN (English-Indian) locale on a Windows 2003 server in work. The LDML was exported from a Windows 2008 machine.

    Dan.

  5. Shawn Steele says:

    Custom locales only work for managed .Net 2.0+ apps on Windows 2003.  So it’d work for an asp.net app, but not for native code or windows itself.  That support was added with Vista/Server2008.