Sample code for getting ELK cultures on other platforms

by Michael S. Kaplan, published on 2006/04/20 03:01 -04:00, original URI: http://blogs.msdn.com/b/michkap/archive/2006/04/20/579579.aspx


Talking about ELKs (Enabling Language Kits) again, those cool things that provide new locales outside of operating system upgrades that I first mentioned in Lions and tigers and bearsELKs, Oh my! way back in January of last year.

More recently, in ELK cultures for other platforms, I answered a question about how to take one of those ELK locales that becomes a Windows Only Culture in the .NET Framework and get it onto a machine that does not contain that locale, such as Windows Server 2003 or Windows 2000 or NT 4.0 or even Windows 98/Me.

But Dave Sussman asked in a comment to that post:

We've hit the same problem with a requirement for Welsh locale support in an ASP.NET 2.0 web application. You don't explain how you create the LDML file and import it into server 2003 - any pointers?

Thanks

dave

So I figured providing a bit of sample code that showed how to do it might be in order....

We will be using the CultureAndRegionInfoBuilder Class, and the following members:

Basically, there are two bits of code to run, one on the XP SP2 machine (or whatever machine contains the locale from which you are getting data):

using System;
using System.Globalization;

namespace Testing {
    class Test {
        [STAThread]
        static void Main(string[] args) {
            CultureAndRegionInfoBuilder carib = new CultureAndRegionInfoBuilder("cy-GB", CultureAndRegionModifiers.Replacement);
            carib.LoadDataFromCultureInfo(new CultureInfo("cy-GB", false));
            carib.LoadDataFromRegionInfo(new RegionInfo("cy-GB"));
            carib.Save(@"c:\cy-GB.ldml");
        }
    }
}

And then the following code on Server 2003 (or whatever version of Windows does not have the locale in question):

using System;
using System.Globalization;

namespace Testing {
    class Test {
        [STAThread]
        static void Main(string[] args) {
            CultureAndRegionInfoBuilder carib = CultureAndRegionInfoBuilder.CreateFromLdml(@"c:\cy-GB.ldml");
            carib.Register();
        }
    }
}

Now to compile these two binaries from the command line, remember to add the reference to sysglobl.dll with the following line:

csc /r:sysglobl.dll welsh.cs

And then you are all set, and you can use the culture in your managed code using version 2.0 of the .NET Framework!

 

This post brought to you by "рай" (U+183d, a.k.a. MONGOLIAN LETTER ZA) 


# Mike on 20 Apr 2006 1:23 PM:

One minor correction: .NET Framework 2.0 does not support Windows NT 4.0.

# Michael S. Kaplan on 20 Apr 2006 2:32 PM:

Truly? How on earth could anyone want to support Win98/Me but *not* support NT4? That's insane! :-)

# Andy Brown on 29 May 2006 7:35 PM:

Wow. I've just started to "localize" (or is it localise) our web application so that we don't have any serious reworking to do as and when we need to put it into other languages, and all your posts are very exciting. Thank you.

And re: "ELK cultures for other platforms", yep, I'm especially interested in using the cy-GB Welsh on our web site straight away. But (sorry, you saw that coming though, right?) I can't get this code to work on my Win server 2003, and I thought you might like to know.

I can pick up the Welsh carib and generate my LDML but then when I run the carib registration on win srv 2003, it fails on the first line:

CultureAndRegionInfoBuilder carib = CultureAndRegionInfoBuilder.CreateFromLdml(@"c:\cy-GB.ldml");

with the error:

Unhandled Exception: System.Xml.Schema.XmlSchemaValidationException: Culture name 'cy-gb' is not supported.
Parameter name: name ---> System.ArgumentException: Culture name 'cy-gb' is not supported.
Parameter name: name

I've tried looking up the schema the ldml uses(http://schemas.microsoft.com/globalization/2004/08/carib/ldml), but can't find it. Is there anything I did obviously wrong?

Andy

referenced by

2010/09/10 Doing the minimum isn't always the best plan...

2006/11/22 Fixing the sample code for getting ELK cultures on other platforms

2006/05/18 Where are the other Tamils?

go to newer or older post, or back to index or month or day