【发布时间】:2015-10-09 18:48:58
【问题描述】:
我有一个包含本地化包的框架。
构建包之前的本地化屏幕截图:
这是我在框架中用来获取包和字符串的代码:
+ (NSBundle*) bundleWithName:(NSString*)name {
NSString *mainBundlePath = [[NSBundle mainBundle] resourcePath];
NSString *frameworkBundlePath = [mainBundlePath stringByAppendingPathComponent:name];
if ([[NSFileManager defaultManager] fileExistsAtPath:frameworkBundlePath]){
return [NSBundle bundleWithPath:frameworkBundlePath];
}
return nil;
}
+(NSString *)localizedStringFromBundleWithKey:(NSString *)keyString
{
return NSLocalizedStringFromTableInBundle(keyString, nil, [Common bundleWithName:@"MyCool.bundle"], nil);
}
然后访问我的本地化字符串:
[infoView setFirstButtonTitle:[Common localizedStringFromBundleWithKey:@"dialog_button_preferences"]];
当我将框架拖放到测试项目中时,它看起来像这样:
如果我将我的设备更改为西班牙语或任何其他语言,测试项目中的字符串都会以英语显示。
然后进一步解决问题 - 如果我将 Localizable.strings 添加到测试项目(除了框架包中的那些),则所有本地化都不起作用,而是显示“关键”名称。
本地化 iOS 框架的正确方法是什么?
【问题讨论】:
-
你为什么不在你的一门课上使用
+ (NSBundle *)bundleForClass:(Class)aClass? -
不知道@Wain 是推荐的方法吗?
-
我也遇到过同样的问题。发现this SO 的答案表明
NSBundle中存在错误。
标签: ios objective-c iphone