How to get system locale and system language in cocoa

Akbar picture Akbar · Jun 8, 2012 · Viewed 8.9k times · Source

I want to get the system default language and system locale.

I have tried the following code snippet to get the system current locale as the following

NSLocale *locale;
locale = [NSLocale systemLocale];

NSString * localLanguage = [locale objectForKey:NSLocaleIdentifier];
NSLog (@"Language : %@", localLanguage); 

NSLog(@"System locale Identifier %@",[locale localeIdentifier]);

But nothing is displayed with System locale Identifier.If it is currentlocale it is giving the correct result.Why system locale is not giving any value and how to get system default language not the user preferred language?please help

Answer

user1458963 picture user1458963 · Nov 26, 2012

You can simply use: NSString* language = [[NSLocale preferredLanguages] objectAtIndex:0];