preferredLanguages
Returns the user's language preference order as an array of strings.
+ (NSArray *)preferredLanguages
Return Value of [NSLocale preferredLanguages]
The user's language preference order as an array of
NSString
objects, each of which is a canonicalized IETF BCP 47 language identifier.
Example of [NSLocale preferredLanguages]
NSArray *languages = [NSLocale preferredLanguages];
for (NSString *language in languages) {
NSLocale *locale = [[[NSLocale alloc] initWithLocaleIdentifier:language] autorelease];
NSLog(@"language code = %@, display name = %@, in language = %@",
language,
[[NSLocale currentLocale] displayNameForKey:NSLocaleIdentifier value:language],
[locale displayNameForKey:NSLocaleIdentifier value:language]);
}
Example of [NSLocale preferredLanguages]
NSString * language = [NSString stringWithFormat:@"%@",[[NSLocale preferredLanguages] objectAtIndex:0]];
language = [NSString stringWithFormat:@"%@",[[NSLocale currentLocale] displayNameForKey:NSLocaleIdentifier value:language]];
NSLog(@"Language=%@",language);
Example of [NSLocale preferredLanguages]
NSPredicate *lenIs2=[NSPredicate predicateWithFormat:@"length==2"];
NSArray *filtered = [[NSLocale preferredLanguages] filteredArrayUsingPredicate:lenIs2];
NSLog(@"%@", filtered);