Iphone – How to get localized list of available iPhone language names in objective-c

iphonelocalizationnslocale

In Objective-C, I can easily get a list of the available Locales, like this:

NSArray *test = [NSLocale availableLocaleIdentifiers];
NSLog(@"%@", test);
for (int i = 0; i < [test count]; i++) {
    NSLog(@"%@", [[NSLocale currentLocale] displayNameForKey:NSLocaleIdentifier value:[test objectAtIndex:i]]);
}

This gives me a list such as this one:

Spanish (United States)
Macedonian (Macedonia)
Oromo (Kenya)
Danish (Denmark)
Korean (South Korea)
Tachelhit (Latin)
Fulah (Senegal)
Indonesian
Serbian (Cyrillic, Montenegro)
Makonde (Tanzania)
Welsh

However, rather than a list of the Locale names, I'd like to get a localized list of language names, as in the Settings app. For example, if the phone is in the US locale, I want to get "English," if the phone is in French, "Anglais," and if in German, "Englisch." What is the best way to accomplish creating such a localized list of language names?

Best Answer

NSArray* languages = [[NSUserDefaults standardUserDefaults] objectForKey:@"AppleLanguages"];

for (int i = 0; i < [languages count]; i++) {

    NSLog(@"%@", [[NSLocale currentLocale] displayNameForKey:NSLocaleIdentifier value:[languages objectAtIndex:i]]);

}