문제

I have an ASP.NET 3.5 website.

Why can't I create a specific culture for the language Bokmal like this:

CultureInfo c = CultureInfo.CreateSpecificCulture("nb");

Language "en" works fine, it results in "en-US". I thought that with "nb" I could do the same thing and get culture "nb-NO". But with "nb" i get the error:

Culture nb is not supported.

I'll explain why I needed it.

I retrieved a list of cultures: "nl-NL", "nl-BE", "nb-NO", "fr-CH", "fr-FR" Want I wanted was a unique list of languages with the default cultures. So I create a list with unique languages which results in "nl", "nb", "fr". Next thing I want the specific cultures but nb doesn't work. I wanted this because the unique list selected nl-BE instead of the default nl-NL.

But then I'll just stick with "nl-BE" when Dutch is selected and place the cultures in a unique cultures list. This list will result in "nl-BE", "nb-NO", "fr-CH".

도움이 되었습니까?

해결책

You cannot assume that there is a correspondence between language names and parent-child relationships between CultureInfo objects. The hierarchy also depends on Windows version.

According to the documentation for the NLS API, the "nb" culture exists on Windows 7, but not on Windows Vista.

On my Windows 7 machine, the culture hierarchy for Bokmål is, in child to parent order

  • nb-NO
  • nb
  • no
  • Invariant culture

In short, you should use the Parent property of the CultureInfo object, instead of doing string manipulations.

다른 팁

I cannot see why this is not working. These three names below gives me Correct Culture

Try:

CultureInfo c = CultureInfo.CreateSpecificCulture("nb-NO");

UnitTest:

        [Test]
    public void CultureTest()
    {
        var c = CultureInfo.CreateSpecificCulture("nb-NO");

        Assert.AreEqual("Norwegian, Bokmål (Norway)",c.DisplayName);
        Assert.AreEqual("nb-NO", c.Name);
        Assert.AreEqual("norsk, bokmål (Norge)", c.NativeName);

        var c2 =
            CultureInfo.CreateSpecificCulture("nb");

        Assert.AreEqual("Norwegian, Bokmål (Norway)", c2.DisplayName);
        Assert.AreEqual("nb-NO", c2.Name);
        Assert.AreEqual("norsk, bokmål (Norge)", c2.NativeName);

        var c3 =
            CultureInfo.CreateSpecificCulture("NO");

        Assert.AreEqual("Norwegian, Bokmål (Norway)", c3.DisplayName);
        Assert.AreEqual("nb-NO", c3.Name);
        Assert.AreEqual("norsk, bokmål (Norge)", c3.NativeName);


    }
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top