Jeff
Jeff

Reputation: 11

culture fallback

I assume the following code is Correct,

CultureInfo culture = CultureInfo.GetCulture("en-US"); Assert.IsTrue(culture.GetConsoleFallbackUICulture().Name == "en");

but it is not, culture.GetConsoleFallbackUICulture().Name is still "en-US", I want to know what is the API to get the fallback culture.

Thanks Jeff

Upvotes: 1

Views: 3427

Answers (2)

Robert McKee
Robert McKee

Reputation: 21487

CultureInfo culture = CultureInfo.GetCulture("en-US");
Assert.IsFalse(culture.IsNeutralCulture); // en-US is NOT Neutral
Assert.IsTrue(culture.Parent.Name == "en"); // Our parent's culture is the neutral english culture
Assert.IsTrue(culture.Parent.IsNeutralCulture); // en is Neutral
Assert.IsTrue(culture.Parent.Parent.Name == ""); // Our grandparent's culture is the invariant culture

Upvotes: 1

Gerrie Schenck
Gerrie Schenck

Reputation: 22368

This is correct, en-US does not need to fallback, that's why it returns en-US.

Only cultures in this list are affected: http://msdn.microsoft.com/en-us/library/system.globalization.cultureinfo.getconsolefallbackuiculture.aspx

EDIT: if you want to do what's in your comment, use the CultureInfo.Parent property.

Upvotes: 3

Related Questions