简体   繁体   中英

Get language and country code (ISO 639-1)

Is there a solution for xamarin-ios to get the current culture in the format like (en_US, de_CH, ..)? I read so many articles in the web and here on stackoverflow. But I can't find a nice solution for this.

Following code snippet returns not this format everytime. Sometimes I get "gsw_DE" and so on (ISO 639-2 instead of 639-1)

NSLocale.CurrentLocale.Identifier;

My current solution is to do it by myself:

var languagecode = NSLocale.PreferredLanguages[0];

var result = String.Format("{0}_{1}", languagecode.Substring(0, 2), NSLocale.CurrentLocale.CountryCode);

Above workaround is from: Get iOS current language (including country code)

I need to make sure that I get the value in this format. Is there another way? Thanks

We are still in the C# world, aren't we? You can use CultureInfo.CurrentUICulture.Name and it'll give you "en-US" for "default" English and "en-GB" for English UK. Language settings are in General - Language & Region - iPhone Language.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM