2

在 iOS9 设备上安装我的应用时出现问题。现在,所有字符串都在法语设备上翻译成英语而不是法语。

NSString * temp  = NSLocalizedString(key, @""); //<-- incorrect English translation
NSString * temp2 = [[NSBundle mainBundle] localizedStringForKey:key value:@"" table:nil]; //<-- incorrect English translation

NSString * frenchBundlePath = [[NSBundle mainBundle] pathForResource:@"fr" ofType:@"lproj"];
NSString * temp3 = [[NSBundle bundleWithPath:frenchBundlePath] localizedStringForKey:key value:@"" table:nil]; //<-- CORRECT

所以我的法语本地化字符串存在并且是正确的,但是 [NSBundle mainBundle] 接缝是英文的......

编辑:

在 iOS7 和 iOS8 [[NSBundle mainBundle] preferredLocalizations]返回fr

在 iOS9 [[NSBundle mainBundle] preferredLocalizations]返回基础

所以我该怎么做 ?

编辑 2:我找到了解决方法,但对它并不满意

NSString * preferedLanguage = [[[[NSLocale preferredLanguages] objectAtIndex:0] componentsSeparatedByString:@"-"] objectAtIndex:0];
NSString *preferedBundlePath = [[NSBundle mainBundle] pathForResource:preferedLanguage ofType:@"lproj"];
NSBundle *preferedBundle = [NSBundle bundleWithPath:preferedBundlePath];
NSString *preferedString = [preferedBundle localizedStringForKey:key value:fallbackString table:nil];
4

0 回答 0