如何在Objective-C中访问Settings.bundle中的本地化字符串?

时间:2019-02-25 13:37:50

标签: objective-c

我需要访问Settings.bundle并获取带有本地化字符串的描述和标题。

Settings.bundle

2 个答案:

答案 0 :(得分:1)

使用NSLocalizedStringFromTableInBundle功能。使用捆绑软件的URL创建NSBundle的实例,并将其用作bundle的参数。使用“根”作为tbl参数的表名。

例如:

NSBundle *bundle = [[NSBundle alloc] initWithURL: ...];
NSString *string = NSLocalizedStringFromTableInBundle("SOME_KEY", "Root", bundle, "Comment");

答案 1 :(得分:1)

最后我是这样做的:

NSString *resourcePath = [[NSBundle mainBundle] pathForResource:@"Settings" ofType:@"bundle"];
NSBundle *settingsBundle = [NSBundle bundleWithPath:resourcePath];
NSURL *url = [settingsBundle URLForResource:@"Root" withExtension:@"plist"];
NSDictionary *dictionary = [[NSDictionary alloc] initWithContentsOfURL:url];
NSArray *preferences = dictionary[@"PreferenceSpecifiers"];

for (NSDictionary *dic in preferences){
    NSString *localizedTitle = NSLocalizedStringWithDefaultValue(dic[@"Title"], @"Root", settingsBundle, dic[@"Title"], @"");
}