Can create culture for en-EN on local dev machine

旧街凉风 提交于 2019-12-02 12:00:14

问题


I just deployed our application to our azure staging environment and ran into an issue with the en-EN culture not being supported. After some digging I find out that there is no such culture, and I should use en-GB or en-USinstead.

But, now to my question. On my local development machine I've got no problems creating a CultureInfo with en-EN.

CultureInfo ci = new CultureInfo("en-EN"); 
Console.WriteLine("culture: "+ ci.ThreeLetterISOLanguageName);

Outputs culture: eng

I also tried enumerating all cultures with CultureInfo.GetCultures(CultureTypes.AllCultures); and there's no corresponding en-EN culture in the result.

So, what's going on, why can I create a culture which shouldn't exist?


回答1:


If you are using Windows 10 the culture behaviour has changed: "unkown", but "maybe existing" cultures (3-letter iso) will only result in an "Unkown locale" culture with LCID 4096. Pre-Windows 10 this would result in an exception (unless you have installed such a custom culture)

MSDN-Link

        try
        {


            // ok
            CultureInfo culture1 = new CultureInfo("foo");
            CultureInfo culture2 = new CultureInfo("xyz");
            CultureInfo culture3 = new CultureInfo("en-xy");

            // not ok - exception
            CultureInfo culture4 = new CultureInfo("foox");

        }
        catch (Exception exc)
        {

        }



回答2:


As the documentation states:

Starting with apps that run under the .NET Framework 4 or later on Windows 7 or later, the method attempts to retrieve a CultureInfo object whose identifier is name from the operating system; if the operating system does not support that culture, and if name is not the name of a supplementary or replacement culture, the method throws a CultureNotFoundException exception.

So basically, your OS has en-EN as an alternate name of an existing culture (more likely en-US) while it's not there on the Azure VM.

The solution is: use a real culture name (which you can find here)



来源:https://stackoverflow.com/questions/34138398/can-create-culture-for-en-en-on-local-dev-machine

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!