.NET CultureInfo difference between ru and ru-RU
Asked Answered
I

2

5

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

Increate answered 15/10, 2013 at 10:2 Comment(13)
Aren't the ru & ru-Ru both are Russian culture name ???Persia
"is different" in what way? @Maris: Don't shout! Also, no need to be offensive Sriram.Boling
@Tim Schmelter. Its the difference instances of a class CultureInfoIncreate
Sorry. But I have spended something like 3 hours to find the problem with the localization.Increate
@Maris: What was the problem with the localization? It's still not clear what was the issue and how you have detected a difference between both cultures. It might help if you'd show the code where you get the current selected language.Boling
@TimSchmelter His question asking Microsoft is not drunk made me to register a comment like that.Strafe
Coming back to the question, There will be minor differences in related-cultures. One will be traditional another will be based on the Region or the geo location of the language being spoken, etc etcStrafe
@SriramSakthivel: I know. But Microsoft is drunk is just a one-liner to an impersonal institution. Calling certain people drunken is an offence.Boling
Equals will return false because both are different identical cultures. There may be or may not be differences in properties or those cultures.Strafe
Agree Tim, and @Increate Sorry if I offended you. We're here to help. Just forget. lets look at the problem :)Strafe
No problem. Actually I didn't find offensive when someone call me drunked. ))) So never mind. Thank you for your answers. I also found that "ru-RU" cultureInfo instance have the field - Parent which contains link to the "ru" culture. So here is a kind of hierarchy.Increate
The think which was disapointed me that the Microsoft didn't used the ISO standards for their CultureInfo. Thats why I called Microsoft - drunk. So the TwoLetterISOLanguageName propertie is not the unique key for the CultureInfo.Increate
Remember that many languages are spoken in more than one region or country. For example Russian is spoken (by some minority) in many countries, like Kazakhstan or Latvia, so in the future .NET may include cultures ru-KZ or ru-LV, besides ru-RU. Already, a language like Spanish has many CultureInfo (about 20) including es-ES (Spanish (Spain)), es-AR (Spanish (Argentina)), es-US (Spanish (United States)).Coquelicot
C
12

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.

Cadwell answered 15/10, 2013 at 10:18 Comment(0)
A
8

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

Amoeba answered 15/10, 2013 at 10:18 Comment(2)
You are wrong about the demo #2. I've run this: var culture = CultureInfo.GetCultureInfo("ru"); Thread.CurrentThread.CurrentCulture = culture; Without any runtime exception.(.NET 4.5)Increate
@Increate A demo is a demo: it demonstrates a fact that there is an implementation of C# (which happens to be Mono) that would crash when you do a certain thing. The fact that it does not crash on other systems is encouraging, but I think it's nice to know that it's not universally safe. I edited the answer to reflect your comment.Amoeba

© 2022 - 2024 — McMap. All rights reserved.