I am using a single, localized Storyboard for my application. The app has to have an option to change language on the fly. So far I figured out how to change the language which is used during the app launch:
[[NSUserDefaults standardUserDefaults] setObject:[NSArray arrayWithObjects:@"de", @"en", @"fr", nil] forKey:@"AppleLanguages"];
[[NSUserDefaults standardUserDefaults] synchronize]; //to make the change immediate
And managed to reload my entire application by removing all subviews of the key window, reloading the initial view controller from the storyboard and making it the new root view controller. (It has some problems, like managing open resources, but it can be done.)
The only thing I couldn't figure out is how do I force iOS to reload the storyboard in the new language? It seems storyboards are cached somehow, and -UIStoryboad:stroyboardWithName:fromNib
does not reload it entirely, so it appears in the last language.
I've already considered two other options:
having different storyboard files for each language (it is unamanageable, I don't want to do this)
using event listeners in all of my view controllers which respond to a language change and set the new strings on the UI (which is also has to be called every time any interface element gets instantiated from the storyboard). This solution requires more time, than we'd like to spend with this, and also highly increases the possibility of bugs.
Is there some more clever way? I don't want to keep the current state of my application, so restarting it like it was killed and realunched seems a reasonable resolution.