首选语言 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" 等其他值,那么您应该拆分 -
字符上的 >language.即使你只是得到fr",这也可以工作.
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屋!
查看全文