Reputation: 45941
I'm developing a Windows Phone app.
How can I get the language code from CultureInfo.CurrentCulture?
I'm using CultureInfo.CurrentCulture.Name and I getting 'en-US'. I only need en.
Upvotes: 2
Views: 2218
Reputation: 3276
I'm not sure exactly what you are trying to achieve. If all you want is to remove the region, retaining the script distinction (if you are interested in zh-Hans for example and not just zh) then you will want to use the Parent property (). Though this can return legacy (zh-CHS) so you would want to use the IetfLanguageTag property to resolve that:
CultureInfo.CurrentCulture.Parent.IetfLanguageTag
en-US -> en
zh-CN -> zh-Hans
zh-TW -> zh-Hant
Sometimes it still isn't going to give you the expected answer since it will only language tags that are supported (but this isn't any different from the TwoLetterISOLanguageName property):
az-Cyrl-AZ -> az
az-Latn-AZ -> az
And it seems like some of the chains were omitted:
sr-Cyrl-BA -> (Invariant)
You can check for invariant and then return the TwoLetterISOLanguageName property to work around that.
Upvotes: 1