I am using the code below to switch to a language:
-(void) switchToLanguage:(NSString *)lang{
[[NSUserDefaults standardUserDefaults] setObject:[NSArray arrayWithObjects:lang, nil]
forKey:@"AppleLanguages"];
[[NSUserDefaults standardUserDefaults] synchronize];
[sliderViewController refreshView];
}
I am not sure if it is right. After that, in the refresh view function of sliderViewController:
-(void)refreshView{
slideLabel.text = NSLocalizedString(@"To Menu", @"To Menu");
slogan.text = NSLocalizedString(@"Categories", @"Categories");
}
But it doesn’t work. Where am I wrong?
Setting the
AppleLanguageskey only works in yourmain.mfile, beforeUIApplicationMainis called. If you try and change its value at any other time it will not work.If you want support for changing the language at runtime, you will have to roll your own localization functions.