I have been facing a problem with iOS Programming since its the first time I'm using Localization,,
I used the following to know which lang I'm having:
- (NSString*) getLanguage{
NSArray* languages = [[NSUserDefaults standardUserDefaults] objectForKey:@"AppleLanguages"];
NSString *preferredLang = [languages objectAtIndex:0];
return preferredLang;}
and there is button to change the lang That calls function to change the lang
- (void) setLanguage:(NSString*) l{
[[NSUserDefaults standardUserDefaults] setObject: [NSArray arrayWithObjects:l, nil] forKey:@"AppleLanguages"];
[[NSUserDefaults standardUserDefaults]synchronize];}
The language changes successfully, but I need to close and reopen the app to see the result, is there any other way to change the localisation automatically after switching lang?
NOTE: it should woke with storyboards too.
As @Tudorizer describes in this link after you translate your files
use this solution:
Put this macro in the Prefix.pch:
and where ever you need a localized string use:
To set the language use:
Multiple times: