Multiple storyboards don't load localization

I have an application that has several different storyboards and uses basic internationalization for French localization. Main.storyboard, which has a .strings file with translation, loads with French just fine. However, when I create a new storyboard and submit it, it remains in English. I just did this to load the storyboard earlier:

UIStoryboard *upcomingStoryboard = [UIStoryboard storyboardWithName:storyboardName bundle:nil];
/// Code to present initial view controller.

      

It just loads the English storyboards. Then I tried to follow the instructions from this site , which changed my code to:

NSString *language   = @"Base";
NSBundle *mainBundle = [NSBundle mainBundle];
NSString *preferred  = [[mainBundle preferredLocalizations] objectAtIndex:0];
if ([[mainBundle localizations] containsObject:preferred]) {
    language = preferred;
}
NSBundle *bundle = [NSBundle bundleWithPath:[mainBundle pathForResource:language
                                                                 ofType:@"lproj"]];
UIStoryboard *upcomingStoryboard = [UIStoryboard storyboardWithName:storyboardName bundle:bundle];

      

All of this caused the app to crash when loading the storyboard, which is probably due to the fact that there is no real storyboard file in the file fr.lproj

, just in the file .strings

. Has anyone had any success with this?

+3


source to share


1 answer


I am using multiple storyboards in my localized app. None of them are specified as the "Main Interface" file. All of them are loaded into the code depending on where the user should be in the application.

Basically I have a login storyboard that allows the user to login and an app storyboard for the application.

The project uses basic internationalization (with English as development language) and strings files for all translations (nibs, storyboards and code).



They are loaded using a method like this ...

- (void)showStoryboardWithName:(NSString *)storyboardName transition:(UIViewAnimationOptions)transition
{
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:storyboardName bundle:[NSBundle mainBundle]];
    UIViewController *controller = [storyboard instantiateInitialViewController];
    [self showViewController:controller withTransition:transition];
}

      

I have 15ish languages ​​localized in the application and they all work with this.

0


source







All Articles