I was working with language localisation .I want to change the language of my application whenever i select a language from a drop down list which is present in my application 开发者_运维技巧, that is it should change the language without changing the language of device .please suggest me how can i implement
Thanks in advance
Have a look at this: How to force NSLocalizedString to use a specific language
You can do this, but it won't play nicely with the built in localization functions in Foundation (e.g. NSLocalizedString
), so you'll need to ignore them and write your own string-getting function, XIB-loading path, etc.
The question and answer here covers how to access localizations in the bundle on the fly like this: Overriding preferred strings localization on the fly for testing
You can force the "AppleLanguages" user default. The example below shows how can be done; in particular here I'm switching the first (default) with the second language.
NSArray *lang = [[NSUserDefaults standardUserDefaults] arrayForKey:@"AppleLanguages"];
NSLog(@"current lang: %@",lang);
[[NSUserDefaults standardUserDefaults] setObject:[NSArray arrayWithObjects:
[lang objectAtIndex:1],
[lang objectAtIndex:0],
nil]
forKey:@"AppleLanguages"];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSMutableArray *languages = [NSMutableArray arrayWithArray:[defaults objectForKey:@"AppleLanguages"]];
[languages replaceObjectAtIndex:0 withObject:@"fr"];
[defaults setObject:languages forKey:@"AppleLanguages"];
[defaults synchronize];
This is setting the language to French. Just put on position 0 what language you want to be loaded.
精彩评论