Reputation: 781
I developed multi language, navigation controller based application. The main menu of the application have also and settings screen at below. User can change to application language with language button pressed. I want to refresh main menu screen and also settings screen language When user changed language But i did not.
Upvotes: 2
Views: 846
Reputation: 348
make a method (which returns a dictionary of language strings loaded from plist) in the AppDelegate. Whenever user selects a language set the NSUserDefaults accordingly, and call that method in app delegate. Now use this method in viewWillAppear of every controller and get the desired language dictionary and load your views.
-(NSMutableDictionary*)getCurrentLanguageDictionaryFromResource
{
NSString *defaultPath;
defaultPath = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"%@.plist",[self getAppCurrentSettingsLanguage]] ofType:nil];
if(languageDictionary !=nil)
{
[languageDictionary release];
languageDictionary=nil;
}
languageDictionary = [[NSMutableDictionary alloc] initWithContentsOfFile:defaultPath];
return languageDictionary;
}
Upvotes: 0
Reputation: 458
Keep in mind, that Apple discourages language selection in the app. The best solution is to just localize your Views and use NSLocalizableString, and just let the language in the app follow the language of the phone's settings.
Upvotes: 1
Reputation: 4546
NSString *path = [[NSBundle mainBundle] pathForResource:@"nl" ofType:@"lproj"];
NSBundle *bundle = [NSBundle bundleWithPath:path];
NSString *englishWord = @"translate";
NSString *translation = [bundle localizedStringForKey:englishWord value:englishWord table:nil];
NSLog(@"%@ = %@", englishWord, translation);
// nl.lproj/Localizable.strings:
"translate" = "vertaal"
Upvotes: 4
Reputation: 6587
You need to restart application, if you want to change language.
For this, you can use local notifications to again restart your application with proper message showing user that your application will get re-started now.
Hope this description helps you......
Upvotes: -1