Manually loading a different localized nib in iOs

So, just like I said in the edit, this is what I found as a solution:

NSString* path= [[NSBundle mainBundle] pathForResource:@"de" ofType:@"lproj"]; 

NSBundle* languageBundle = [NSBundle bundleWithPath:path];

self.currentController = [[newClass alloc] initWithNibName:@"CustomController" bundle:languageBundle];

And if you need to load a text into a localized label

NSString* path= [[NSBundle mainBundle] pathForResource:[[[NSUserDefaults standardUserDefaults] objectForKey:@"AppleLanguages"] objectAtIndex:0] ofType:@"lproj"];

NSBundle* languageBundle = [NSBundle bundleWithPath:path];

someLabel.text = [languageBundle localizedStringForKey:@"textKey" value:@"" table:nil];       

More info here: http://learning-ios.blogspot.com/2011/04/advance-localization-in-ios-apps.html

To whom it may concern, this method raises quite a number of problems.
For starters, something that might affect everyone: you need to have every resource used by a localized xib also localized.
If I load a new localized xib using this method, and that xib contains a regular non-localized image, it won’t show up until it’s localized.
The other problems are more particular and are connected to the way you retrieve the localized data.

In the end, I don’t think I will be using this, because for the current app it’s way too problematic, but it might turn out handy in the future.

Leave a Comment