ios - Localizable.strings 在 iOS 框架中不起作用

标签 ios objective-c iphone

我有一个包含本地化包的框架。

构建捆绑包之前的本地化屏幕截图:

enter image description here

这是我在框架中用来获取包和字符串的代码:

+ (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"]];

当我将框架并捆绑到测试项目中时,它看起来像这样:

enter image description here

如果我将设备更改为西类牙语或任何其他语言,则测试项目中的字符串都会以英语显示。

然后进一步解决问题 - 如果我将 Localizable.strings 添加到测试项目(除了框架包中的项目),则任何本地化都不起作用,而是显示“关键”名称。

本地化 iOS 框架的正确方法是什么?

最佳答案

一个应用程序可以由多个包组成,因此并非所有资源都是主包的一部分。使用+ (NSBundle *)bundleForClass:(Class)aClass使用您的一个类来为您的资源获取正确的捆绑包。

关于ios - Localizable.strings 在 iOS 框架中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33045233/

相关文章:

ios - xlpagertabstrip 一些未完全显示的标签

ios - 如何让 iqkeyboardmanager 包含 UISearchBar

ios - 如何分离输入字符串并在 TableView 中填充它重复了多少次并将索引传递给下一个

objective-c - 保留/释放保留属性的合成 Setter

iphone - 本地通知有 2 个选项 1.oK 和第二个本地通知操作 View 或其他任何内容

ios - 如何更改核心数据中的记录值

ios - deleteRowsAtIndexPaths : swipe to delete rows never deallocates the cell?

ios - 从整数(int 或 NSInteger)到 UICollectionView 的 NSIndexPath*

iphone - Sencha Touch 和保存本地媒体

ios - 各种UIgesture是否优先于touchbagan?