首选语言iOS 9 [英] preferredLanguages iOS 9
本文介绍了首选语言iOS 9的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为了本地化我的应用程序,我使用以下代码:
in order to localize my App, I use the following code:
NSString * language = [[NSLocale preferredLanguages] objectAtIndex:0];
if ([language isEqualToString:@"fr"]) {
}else{
}
但是从iOS 9开始,我必须将"fr"替换为"fr-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 ?
谢谢
推荐答案
如果language
返回其他值,例如"fr-FR"和"fr-CA",则应在
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 {
}
这篇关于首选语言iOS 9的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文