I use this line of code to change the language in my app
[[NSUserDefaults standardUserDefaults]
setObject:[NSArray arrayWithObjects:@"en", @"fr", nil]
forKey:@"AppleLanguages"];
Changes won't take place before the user restarts the app. Do the user really need to restart the app before the changes will take place, or is it possible to just reload th开发者_开发百科e view controllers in some way to make the app change its language immediately.
write below method in your appDelegate class
+(void)GetLangKey:(NSString *)Langkey
{
NSString *tmpstr=[NSString stringWithFormat:@"%@",[[NSBundle mainBundle]pathForResource:@"LanguageResources" ofType:@"bundle"]];
tmpstr =[tmpstr stringByAppendingString:@"/"];
tmpstr=[tmpstr stringByAppendingString:Langkey];
tmpstr =[tmpstr stringByAppendingString:@".lproj"];
// NSLog(@"%@",tmpstr);
myLocalizedBundle=[NSBundle bundleWithPath:tmpstr];
}
and call this method when your language change
if([language isEqualToString:@"English"])
{
[app_obj GetLangKey:@"en"];
}
else
{
[app_obj GetLangKey:@"fr"];
}
精彩评论