Norwegian language code change

July 7th 2023 .NET

As I was recently updating an old .NET Core 3.1 project to .NET 6, I encountered an unexpected breaking change. I couldn't find any documentation about it, even after I already knew about it. Fortunately, I noticed it before deploying the application to production thanks to the test coverage.

In .NET Core 3.1, the ISO 639-1 two-letter language code for the no-NO locale was surprisingly nb (Norwegian Bokmål) and not no (Norwegian macrolanguage):

[Test]
public void NorwegianLanguageCodeIsNbInNetCore31()
{
    var cultureInfo = new System.Globalization.CultureInfo("no-NO");

    cultureInfo.TwoLetterISOLanguageName.Should().Be("nb");
}

I had some extra code in my project to compensate for that and ensure that everything still worked as expected. I had to remove that extra code after I updated the project to .NET 6 because the language code returned for the same locale has changed with .NET 5:

[Test]
public void NorwegianLanguageCodeIsNoInNet5()
{
    var cultureInfo = new System.Globalization.CultureInfo("no-NO");

    cultureInfo.TwoLetterISOLanguageName.Should().Be("no");
}

You can find a test project showing the difference in behavior between the two .NET versions in my GitHub repository. Feel free to try it out yourself and even test it with other .NET versions.

The breaking change in the language code wasn't a big deal in the end, but that was only because I had a thorough enough test coverage to detect it before deploying the new code to production. And it still bothers me that I couldn't find any documentation for the change and the reasoning behind it.

Get notified when a new blog post is published (usually every Friday):

Copyright
Creative Commons License