Mansour Mansour - 5 months ago 42
Objective-C Question

preferredLanguages iOS 9

in order to localize my App, I use the following code:

NSString * language = [[NSLocale preferredLanguages] objectAtIndex:0];
if ([language isEqualToString:@"fr"]) {
}else{
}


But since iOS 9, I'have to replace "fr" by "fr-FR". The problem is that only works for France. How can I support all the other regions (Canada, Belgium,..) ? and the "general setting" for french ?

Thanks

Answer

If language is returning other values such a "fr-FR" and "fr-CA", then you should split language on the - character. This will work even you simply get "fr".

NSString *firstLanguage = [[NSLocale preferredLanguages] firstObject];
NSString *language = [[firstLanguage componentsSeparatedByString:@"-"] firstObject];
if ([language isEqualToString:@"fr"]) {
} else {
}
Comments