1

I've inherited a project that already uses this approach to dynamically switch from one localization to another when it comes to strings translation.

The gist is straight forward.. based the on the language chosen by the user.. identify the localized strings file (ie /path/to/app/Resources/Storyboard/en.lproj) and then use something like

NSLocalizedStringFromTableInBundle(text, @"", [LanguageGateway currentLocalizedBundle], nil) 

to localize the strings. So far so good.

The problem happens when I try to do the same thing with storyboards. I've created two localized versions of my storyboards (taking inspiration from this tutorial.. but the main difference was that i couldn't select the use base internationalization option b/c I simply couldn't select the base files) and then somewhere in my localize method I had this:

- (void)launchLocalized {
    NSLog(@"switching to bundle %@", [LanguageGateway currentLocalizedBundle]);
    storyBoard_ = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:[LanguageGateway currentBundle]];

in my logs I got this:

switching to bundle NSBundle </path/to/App.app/en.lproj> (not yet loaded)
Could not load the "aboutUsMenuButton.png" image referenced from a nib in the bundle with identifier "(null)"
Could not load the "feedbackMenuButton_ar.png" image referenced from a nib in the bundle with identifier "(null)"

so apparently the localized bundle is taking a while to load. and as a result weirdness happens (ie it cannot fetch the images properly and things go haywire).

question: how can I get around this? is there a way to avoid this race condition and wait till the bundle has actually been loaded before fetching the images from it? In most tutorials (like the one I referenced) they rely on exiting the app, then changing the phone language settings.. I don't want that to happen.. I want the use to be able to switch languages within the app itself.

Community
  • 1
  • 1
abbood
  • 23,101
  • 16
  • 132
  • 246

0 Answers0