I\'m trying to add an option for the user to switch between Arabic & English language from inside the app (without having to re-set the language of the whole iPhone), I
I had same issue :(.. and what worked for me (for such scenarios to switch language) ..
You have 2 possibilities..
1) If you want to change the storyboard (hot change), you must modify all your Outlets in the each Storyboard. Choose in your storyboard the desired image (with different names), labels, etc.. For me, with localized images (same name) - only worked after restart of the application.. For the same img_name, I' tried ... to "call" the specific image.. from the specific lproj folder (languageBundle).. but it did not work at changed the storyboard from AppDelegate..
2) You can have only one storyboard... and change only labels, image, etc... (according to Localizable.strings), something linke this... https://stackoverflow.com/a/12149553/1702413 Also, you must have different file name for images (for "hot changing")
I don't know if a bug... or what is...
UPD
You have a little project https://dl.dropbox.com/u/19438780/test5%20copy2.zip with both..
If you are changing the storyboard (like you) you will have the same path for languageBundle until you restart the application. So.. you must do the changing right in your storyboard..
For the second.. you can change/recall outlets .. from specific languageBundle (lproj folders)..
For 1) .. I found a "trick" to overwrite the languageBundle until restart:
-(id) initWithCoder:(NSCoder *)aDecoder{
self = [super initWithCoder:aDecoder];
if (self) {
NSArray* languages = [[NSUserDefaults standardUserDefaults] objectForKey:@"AppleLanguages"];
Lang2 = [languages objectAtIndex:0]; //NSString
}
return self;
}
and init the Outlets:
- (void) viewWillAppear:(BOOL)animated
{
[super viewWillAppear:YES];
NSString *path;
if([Lang2 isEqualToString: @"ro"])
{
path = [[NSBundle mainBundle] pathForResource:@"ro" ofType:@"lproj"];
NSLog(@"enc ro");
}
else{
path = [[NSBundle mainBundle] pathForResource:@"en" ofType:@"lproj"];
NSLog(@"enc en");
}
NSBundle* languageBundle = [NSBundle bundleWithPath:path];
//find and return the desired string
self.label.text=[languageBundle localizedStringForKey:@"kLabelText" value:@"" table:nil];
self.img.image = [UIImage imageNamed:[languageBundle localizedStringForKey:@"myImage" value:@"" table:nil]];
}