Switching between localized storyboard at runtime
Asked Answered
S

1

9

I have iPhone application using storyboard with two language (Arabic / English) how i can switch from Arabic localization storyboard to English storyboard without need to change language iPhone settings (At run time)

Seltzer answered 10/1, 2013 at 14:2 Comment(7)
Don't localize your storyboard, then query a set of custom localized strings. Honestly, changing the language is the only system-sanctioned way of localization, short of writing your own solution.Counterproductive
I don't agree with you i have change the application language at run time in xib not in storyboardSeltzer
so what have you tried then?Counterproductive
I use it in Xib but the solution is different in storyboard , how can i specify launching storyboard with specific languageSeltzer
Hm... If you wanted to you could duplicate either the English or the Arabic storyboard, then individually localize them to one language each. At that point, just use some condition to pick the one you want to load. Should work like a charm if you load the storyboard programmatically, instead of using the whole "Main Storyboard" thing from the info.plist. Switching at runtime, now that's a whole different animal.Counterproductive
You cannot do this, and there is no good reason to want to do so. Just stick with the Apple sanctioned mechanism - this is how users expect apps to behave.Adur
there are many customers here in middle east require the app to have two languages : arabic & english, and the app should switch between two languages at run time without having to go to system settings and change the whole iphone language to Arabic, and this is so reasonable, and I wonder why CodaFi doesn't recommend such thing although it might be a project requirement !Gannes
S
8

I have resolved you can do it as the following below code :

 UIStoryboard *storyBoard;
 if ([language isEqualToString:@"ar"]) {
   lan = [[NSLocale preferredLanguages] objectAtIndex:0];
   storyBoard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone5Arabic" bundle:bnd];
 }
 else if([language isEqualToString:@"en"]) {
    NSLog(@"DDD ");
    lan = [[NSLocale preferredLanguages] objectAtIndex:20];
    storyBoard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone5English" bundle:bnd];
 }
 NSBundle *bnd = [NSBundle bundleWithPath:[[NSBundle mainBundle]pathForResource:lan ofType:@"lproj" ]];



UIViewController *initViewController = [storyBoard instantiateInitialViewController];
[self.window setRootViewController:initViewController];
Seltzer answered 12/1, 2013 at 5:54 Comment(3)
Hello! I got equal answer for this question, but when I change language in runtime and reload needed storyboard images isn't loaded with log message: Could not load the "readability.png" image referenced from a nib in the bundle with identifier "(null)"Whidah
Oh, this is a bug in storyboard localization therefore you need to create different storyboard without using localization.Seltzer
Hello , i'm doing a project which is supported by two language En & Arabic in XIb's i handled by two xibs in storyboard i was surfing and hooked up with above solutions , can you pls elaborate and explain how this will work? @SeltzerButene

© 2022 - 2024 — McMap. All rights reserved.