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

5.5k views Asked by At

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?

2

There are 2 answers

1
chunxi On 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]]);

}
0
Vitaliy On

You can use also this code:

NSArray *test = [NSLocale availableLocaleIdentifiers];
NSLog(@"%@", test);

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

It shows more of languages.