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 https://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 https://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 https://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 https://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 https://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 https://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
- Anonymous
November 28, 2005
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. - Anonymous
December 01, 2005
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. - Anonymous
February 17, 2006
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. - Anonymous
May 26, 2009
The comment has been removed - Anonymous
June 01, 2009
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.