Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone Localization - Get the phone's language code?

I'm localizing my iPhone app for multiple languages, and in addition to changing some of the strings I need to change some backgrounds. Is it possible to query the iPhone and get the user's language code?

Thanks!

like image 587
John Frankes Avatar asked Jan 08 '10 22:01

John Frankes


2 Answers

Take a look at NSLocale:

NSString   *language = [[NSLocale currentLocale] objectForKey: NSLocaleLanguageCode];
NSString   *countryCode = [[NSLocale currentLocale] objectForKey: NSLocaleCountryCode];
like image 188
Ben Gottlieb Avatar answered Oct 23 '22 00:10

Ben Gottlieb


solved my own question!

NSString *language = [[NSLocale preferredLanguages] firstObject];
if (!language) {
   language = @"en";
}
NSLog(@"The device's specified language is %@", language);

Swift version :

var language : String! = "en"
if let lng = NSLocale.preferredLanguages().first {
  language = lng
}
print("The device's specified language is \(language)")
like image 34
John Frankes Avatar answered Oct 23 '22 00:10

John Frankes