How can I get the ISO language code in iOS?

How can I get the current ISO language code in iOS?

+3
source share
3 answers

Check out the Apple Doc for Internationalization Programming Topics

+2
source

[[NSLocale currentLocale] localeIdentifier]will give you a string that is closer to what you are looking for. For my device here in the USA, I get "en_US".

If you want a more standard looking "en-US", you can use instead [[[NSLocale currentLocale] localeIdentifier] stringByReplacingOccurrencesOfString:@"_" withString:@"-"].

, [[NSLocale currentLocale] localeIdentifier] [NSLocale componentsFromLocaleIdentifier:], NSDictionary. NSLocaleLanguageCode, NSString .

+3
NSString *isoCode = [[NSLocale preferredLanguages] objectAtIndex:0];

This will return a 2-digit iso code for the selected language on the device. "en" for English, "de" for German, etc. Hope this helps!

0
source

Source: https://habr.com/ru/post/1771943/


All Articles