Reputation: 738
in my application I must have two languages, but the problem is that they should be switched by pressing a button in the application (on the first screen, or screen settings). As I understand, all the methods of localization
(Localizing
the Storyboard
, Localizing Dynamic Strings
) based on the language settings of the iPhone. The only option that comes to my mind - do it by the record in NSUserDefault
about language preference, and in ViewDidLoad
methods of all ViewControllers
check the record about language and in accordance with it set strings, picture and so on. Can it be done on a more clever way?
Upvotes: 0
Views: 166
Reputation: 4005
You have to manually mange the currently selected language into user default and load the bundle folder according to selected language key like, i have done this and worked like charm
if ([currentLanguage isEqualToString:@"fr"]) { // If French.
languageBundle = nil;
NSString* path = [[NSBundle mainBundle] pathForResource:@"fr" ofType:@"lproj"];
languageBundle = [NSBundle bundleWithPath:path];
}
Upvotes: 0
Reputation: 3441
Ya The way you are following for Localization is not up to Mark.
Please Follow this beautiful tutorial http://www.raywenderlich.com/2876/localization-tutorial-for-ios
Upvotes: 0
Reputation: 23271
this tutorial & sample app helpful you more
ios-programming-tutorial-localization-apps
Upvotes: 0
Reputation: 39374
Try this:
If de is the new language selected by the user. Also assure that you are reinitiating the current view.
[[NSUserDefaults standardUserDefaults] setObject:[NSArray arrayWithObjects:@"de", nil]
forKey:@"AppleLanguages"];
See the below link and source code
http://learning-ios.blogspot.com/2011/04/advance-localization-in-ios-apps.html
and here is the code of one sample app https://github.com/object2dot0/Advance-Localization-in-ios-apps
All the best.
Upvotes: 1