Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How neutral culture is mapped to a specific culture in CultureInfo.CreateSpecificCulture method?

I don't know how Neutral Culture is mapped to a Specific Culture. Is it static like below?

en = en-US    
fr = fr-FR    
pt = pt-BR

I checked http://referencesource.microsoft.com/#mscorlib/system/globalization/cultureinfo.cs,44db57d9e190258e,references

& nativeInitCultureData from https://github.com/dotnet/coreclr/blob/master/src/classlibnative/nls/nlsinfo.cpp

but I couldn't understand. Anyone can help?

like image 866
Rajes Avatar asked Feb 02 '16 11:02

Rajes


People also ask

What does the Getcultures method of the CultureInfo class do?

Provides information about a specific culture (called a locale for unmanaged code development). The information includes the names for the culture, the writing system, the calendar used, the sort order of strings, and formatting for dates and numbers.

What is system globalization CultureInfo?

The CultureInfo class specifies a unique name for each culture, based on RFC 4646. The name is a combination of an ISO 639 two-letter lowercase culture code associated with a language and an ISO 3166 two-letter uppercase subculture code associated with a country or region. In addition, for apps that target .

What is CultureInfo CurrentCulture?

The CultureInfo. CurrentCulture property is a per-thread setting; that is, each thread can have its own culture. You get the culture of the current thread by retrieving the value of the CultureInfo. CurrentCulture property, as the following example illustrates. C# Copy.


2 Answers

I don't think there is an exact mapping here.

en and en-US cultures are different based on their LCID property which has 0x0009 and 0x0409 in order. The en is a neural culture that is associated with a language but not with a country or region.

But en-US is a specific culture which associated with both a language and a country or region.

That's why you can create a RegionInfo with en-US

var region = new RegionInfo("en-US");

but you can't create with en

var region = new RegionInfo("en");

which says;

The region name en should not correspond to neutral culture; a specific culture name is required.

There is an hierarchy between CultureInfo objects which the Parent of a specific culture is a neutral culture and the parent of a neutral culture is the InvariantCulture.

Let me visualize it for you how this hierarchy works for en neutral culture:

enter image description here

like image 170
Soner Gönül Avatar answered Oct 31 '22 21:10

Soner Gönül


Almost, there is a parent relationship between cultures. You can see this via:

var specificCultures = System.Globalization.CultureInfo.GetCultures(System.Globalization.CultureTypes.SpecificCultures);
foreach (var culture in specificCultures)
{
     var text = "Specific: " + culture.Name + " Parent: " + culture.Parent.Name;
     Console.WriteLine(text);
}

Giving (extract of output):

Specific: ar-SA Parent: ar
Specific: bg-BG Parent: bg
Specific: ca-ES Parent: ca
Specific: zh-TW Parent: zh-CHT
Specific: cs-CZ Parent: cs
Specific: da-DK Parent: da
Specific: de-DE Parent: de
Specific: el-GR Parent: el
Specific: en-US Parent: en
Specific: fi-FI Parent: fi
Specific: fr-FR Parent: fr
Specific: he-IL Parent: he

You can see from this snippet that the parent of zh-TW is zh-CHT. But that does get down to zh eventually (via zh-Hant). Following a parent of a specific culture will get you down to a neutral one eventually.

like image 26
NikolaiDante Avatar answered Oct 31 '22 21:10

NikolaiDante