6

我正在尝试获取与 NSLocalizedStringFromTableInBundle 一起使用的字符串文件表。

我正在使用这种方法:

+(NSBundle*)getBundleForLang:(NSString*)lang{
     //get the path to the bundle
    NSString *bundlePath = [[NSBundle mainBundle] pathForResource:@"localizable" ofType:@"strings" inDirectory:nil forLocalization:lang];
    NSLog(@"bundlePath = %@",bundlePath);

    //load the bundle
    NSBundle *langBundle = [[NSBundle alloc] initWithPath:[bundlePath stringByDeletingLastPathComponent]];
    NSLog(@"langBundle = %@",langBundle);
    return langBundle;
}

虽然它在模拟器上运行良好,但当我尝试在 iPhone 设备上使用它时,我得到了这个 NSLog:

2011-12-09 00:40:14.533 MyApp[12754:707] langBundle = NSBundle 
</var/mobile/Applications/915E6BCB-EC44-4F1D-891B-EF68E2FA89C2/MyApp.app/he.lproj> 
(not yet loaded)

为什么没有加载,问题出在哪里?

谢谢

沙尼

4

2 回答 2

6

检查文件路径的大小写。模拟器(默认)不区分大小写,而设备是。这可能导致模拟器成功找到文件,但设备失败。

于 2011-12-08T23:01:14.673 回答
1

这不是错误。字符串包,例如 en.lproj,不包含可执行文件。当您尝试 时[bundle loadAndReturnError:],它会失败,并且 loadAndReturnError:' 的文档会告诉您原因。

于 2018-11-25T13:10:30.087 回答