Mansour Mansour - 1 year ago 127
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"]) {

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 ?


Answer Source

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 {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download