获取系统语言,这种方法 获取的是Settings->General->Language&Region->Preferred Language 手机系统的语言,而不是APP呈现的语言
+ (NSString*)getPreferredLanguage {
NSUserDefaults* defs = [NSUserDefaults standardUserDefaults];
NSArray* languages = [defs objectForKey:@"AppleLanguages"];
NSString* preferredLang = [languages objectAtIndex:0];
return preferredLang;
NSArray* languages = [defs objectForKey:@"AppleLanguages"];
NSString* preferredLang = [languages objectAtIndex:0];
return preferredLang;
}
对于国际化的项目,下载的是什么语言的版本,获取的语言应该是下载版本语言,也就是APP呈现的语言,可以直接从本地化的语言列表中取
+ (NSString *)getPreferredLanguage1 {
NSString *preferredLang = [[[NSBundlemainBundle] preferredLocalizations] objectAtIndex:0];
NSString *lagueStr = nil;
if ([preferredLang hasPrefix:@"en"]){
lagueStr = @"en";
} elseif ([preferredLang hasPrefix:@"fr"]) {
lagueStr = @"fr";
} elseif ([preferredLang hasPrefix:@"es"]){
lagueStr = @"es";
} else{
lagueStr = @"en";
}
return lagueStr;
NSString *preferredLang = [[[NSBundlemainBundle] preferredLocalizations] objectAtIndex:0];
NSString *lagueStr = nil;
if ([preferredLang hasPrefix:@"en"]){
lagueStr = @"en";
} elseif ([preferredLang hasPrefix:@"fr"]) {
lagueStr = @"fr";
} elseif ([preferredLang hasPrefix:@"es"]){
lagueStr = @"es";
} else{
lagueStr = @"en";
}
return lagueStr;
}