删除项目的一种语言后,项目中其他现有的可本地化文件无法正确加载。文件包含在捆绑资源中,但它们没有正确加载,加载方法不会返回任何值,因为 localizable.strings 文件中包含的字符串键。
这是加载方法:
-(NSString*) languageSelectedStringForKey:(NSString*) key
{
NSString *path;
NSUserDefaults *currentDefaults = [NSUserDefaults standardUserDefaults];
NSArray *languages = [currentDefaults objectForKey:@"AppleLanguages"];
NSString *selectedLanguage = [languages objectAtIndex:0];
if([selectedLanguage isEqualToString:@"es"])
path = [[NSBundle mainBundle] pathForResource:@"es" ofType:@"lproj"];
else if([selectedLanguage isEqualToString:@"en"])
path = [[NSBundle mainBundle] pathForResource:@"en" ofType:@"lproj"];
NSBundle* languageBundle = [NSBundle bundleWithPath:path];
NSString* str=[languageBundle localizedStringForKey:key value:@"" table:nil];
path=nil;
languages=nil;
selectedLanguage=nil;
languages=nil;
languageBundle=nil;
return str;
}
非常感谢您的帮助。