Question

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".

Was it helpful?

Solution

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.

OTHER TIPS

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);


    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top