Search code examples
c#asp.netculturecountry

ASP.NET Create a specific culture with language code nb (Bokmål)


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


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.