Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET CultureInfo difference between ru and ru-RU

I found one interesting thing in CultureInfo class. I was writting an app in ASP.NET and I was using Thread.CurrentThread.CurrentCulture to get the current selected language and:

Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo(alias);

There was 2 places where I can set the culture of the current thread in one place I was doing like these:

  1. Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("ru");

  2. Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("ru-RU");

Then I suddenly found that the culture (1) is different then culture (2) but both of them are Russian.

Am I doing something wrong or the Microsoft is drunk?

EDIT

@Tim Schmelter

        var culture = CultureInfo.GetCultureInfo("ru");
        var culture2 = CultureInfo.GetCultureInfo("ru-RU");
        if (Equals(culture, culture2))
        {
            Console.Write(true);
            return;
        }
        Console.Write(false);

The question is - "why does Microsoft separates "ru" and "ru-RU"?

like image 846
Maris Avatar asked Dec 01 '22 18:12

Maris


2 Answers

That's because CultureInfo.GetCultureInfo("ru") returns NeutralCulture while CultureInfo.GetCultureInfo("ru-RU") returns SpecificCulture. Actually, SpecificCulture derives from NeutralCulture. So the asnwer is no, they are not the same and they have different LCIDs.

In general case you should always use SpecificCulture.

About CultureInfo suggest reading this MSDN article.

like image 83
Fedor Avatar answered Dec 14 '22 15:12

Fedor


The ru culture is neutral, meaning that it cannot be used in formatting and parsing. The ru-RU culture, on the other hand, is specific (demo #1), so you can use it to format and parse your data.

Comparing the pages for the two cultures shows that ru has a subset of settings provided by ru-RU.

Among other things, trying to set a neutral culture as a thread's current culture leads to exceptions (demo #2 on Mono, does not crash on .NET 4.5).

like image 43
Sergey Kalinichenko Avatar answered Dec 14 '22 14:12

Sergey Kalinichenko