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
If
language
is returning other values such a "fr-FR" and "fr-CA", then you should splitlanguage
on the-
character. This will work even you simply get "fr".My fix on my code is simple :
Hey there Don't do like that It will create issue when localization are set different for language having different regions as like
es-mx
andes-cl
. In that case above solution will create issue. Use following code for the solution:In case your have selected
zh-Hans-US
from setting But your app is havingzh-Hans-TW
andzh-Hans-CN
only. That the above code will return you"zh-Hans-TW"
the first preferred Localization.Try this may be useful to you.
Paste my codes in here, maybe help you
You shouldn't split the NSLocale. NSLocale has some Keys, which you can retrieve with
objectForKey:
In your example you can write the following:
[NSLocale currentLocale]
is actually the same as[[NSLocale preferredLanguages] firstObject]
but has some additional information where you can retrieve which decimal separator should be used or which currency symbol.Other relevant Keys can be found in the class reference from apple.