Javier Izquierdo
Javier Izquierdo

Reputation: 11

How can I access to the localized strings inside Settings.bundle in Objective-C?

I need to access to the Settings.bundle and get the descriptions and titles with the localized string.

Settings.bundle

Upvotes: 0

Views: 228

Answers (2)

Javier Izquierdo
Javier Izquierdo

Reputation: 11

In the end I did it this way:

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"], @"");
}

Upvotes: 1

pointum
pointum

Reputation: 3177

Use NSLocalizedStringFromTableInBundle function. Create an instance of NSBundle with URL of your bundle and use it as bundle argument. Use “Root” as the table name for tbl argument.

For example:

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

Upvotes: 1

Related Questions