2

I have a framework that has localizations in a bundle.

Screenshot of localizations before bundle is built:

enter image description here

This is the code I use in my framework to grab the bundle and strings:

+ (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);
}

Then to access my localized strings:

[infoView setFirstButtonTitle:[Common localizedStringFromBundleWithKey:@"dialog_button_preferences"]];

When I drop the framework and bundle into a test project it looks like this:

enter image description here

If I change my device to Spanish or any other language the strings all show up in english in the test project.

Then to further the problem - if I add Localizable.strings to the test project (in addition to the ones in the framework bundle), none of the localizations work and instead show the "key" names.

What is the proper way of localizing an iOS framework?

Spentak
  • 3,359
  • 3
  • 21
  • 31

1 Answers1

0

An application can be made up from multiple bundles, so not all resources are part of the main bundle. Use + (NSBundle *)bundleForClass:(Class)aClass With one of your classes to get the correct bundle for your resources.

Wain
  • 118,658
  • 15
  • 128
  • 151
  • I forgot to mention that my code is already successfully finding/grabing the bundle. I have verified that. Just wont load the proper localized strings – Spentak Oct 10 '15 at 04:02
  • The bundle, or a bundle? Is the resource path correct and actually points to the correct files? – Wain Oct 10 '15 at 08:58
  • So bundleForClass doesn't work because the framework code that calls that is in the framework, but the bundle is not. I have the bundle properly loading now (confirmed) - the the problem still persists where only English is loaded, despite the fact that another language is selected on the system – Spentak Oct 19 '15 at 18:09