开发者

Problem with loading culture from XML using CultureAndRegionInfoBuilder on Windows XP

开发者 https://www.devze.com 2023-01-20 15:53 出处:网络
I have a web application that will use a few different cultures, one of which is es-US (Spanish United States). However, Windows XP do not have any support for the culture es-US. To work around the pr

I have a web application that will use a few different cultures, one of which is es-US (Spanish United States). However, Windows XP do not have any support for the culture es-US. To work around the problem, I've found out that one is supposed to be able to use the CultureAndRegionInfoBuilder. So I looked into CultureAndRegionInfoBuilder and did the following:

On a Windows 7 machine I saved the culture es-US to an XML-file, as follows:

private static void SaveCultureToFile() {
            try {
                CultureAndRegionInfoBuilder cultureAndRegionInfoBuilder = null;
                Console.WriteLine("Saving es-US to xml disc...\n");
                cultureAndRegionInfoBuilder = new CultureAndRegionInfoBuilder("es-US", CultureAndRegionModifiers.Replacement);

                // Populate the new CultureAndRegionInfoBuilder object with culture information.
                CultureInfo ci = new CultureInfo("es-US");
                cultureAndRegionInfoBuilder.LoadDataFromCultureInfo(ci);

                cultureAndRegionInfoBuilder.Save("es-US.xml");

            }

T开发者_StackOverflow中文版hen I have a function that reads the xml, and registeres the culture into the system, as follows:

    private static void RegisterCultureFromDisk() {
        try {
            CultureAndRegionInfoBuilder cultureAndRegionInfoBuilder = null;
            Console.WriteLine("Loading es-US from xml...\n");
            cultureAndRegionInfoBuilder = CultureAndRegionInfoBuilder.CreateFromLdml("es-US.xml");
            Console.WriteLine("Culture is registred to the system...\n");
            cultureAndRegionInfoBuilder.Register();
            Console.WriteLine("The following culture has been registred to the system: \n");

        }

So I run the program using the SaveCultureToFile method on a Windows 7 machine, thus saving the culture to an xml file. Then I copy the files to the Windows XP machine, and runs the same program but the RegisterCultureFromDisk() method. But the program fails in the CultureAndRegionInfoBuilder.CreateFromLdml("es-US.xml") method saying that:

"Culture name 'es-us' is not supported"

Well, thats exactly why I'm trying to load the culture from the xml and registering it into the system.

Do any one know what I'm doing wrong, or how I can create the es-us culture at the Windows XP machine?

Thanx!


I know this is an ancient question, but I've recently run into this issue and managed to actually solve it.

Turns out the CreateFromLdml method can be tricked into loading a non-existing culture if you just create a temporary culture using the name of the one you want to import. Then you can unregister the temporary culture and register the one you just loaded instead.

I've made a simple command-line tool for exporting/importing cultures, which we've successfully used to add in some obscure missing cultures we needed when deploying new servers on Azure.

If you need it - the source code and a more in depth description of the solution is available here.


From MSDN:

Note that a custom culture can be registered on a computer only by a user who has administrative rights on that computer. Consequently, typical applications cannot create a custom culture.

I suspect it might be the cause of your problem... do you have admin rights on this machine ?

0

精彩评论

暂无评论...
验证码 换一张
取 消