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

In Objective-C, I can easily get a list of available locales, for example:

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:

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

However, instead of a list of locale names, I would 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, "English", and if in German "Englisch". What is the best way to create such a localized list of language names?

+3
source share
2 answers
NSArray* languages = [[NSUserDefaults standardUserDefaults] objectForKey:@"AppleLanguages"];

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

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

}
+10
source

You can also use 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 displays more languages.

0
source

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


All Articles