参考:http://blog.csdn.net/yang8456211/article/details/12031667
1.原理。
查看NSLocalizedString(@"abc",nil);的定义。 1 2 | #define NSLocalizedString(key, comment) \ [[ NSBundle mainBundle] localizedStringForKey:(key) value:@ "" table: nil ] |
1 2 3 | #define AppLanguage @"appLanguage" #define CustomLocalizedString(key, comment) \ [[ NSBundle bundleWithPath:[[ NSBundle mainBundle] pathForResource:[ NSString stringWithFormat:@ "%@" ,[[ NSUserDefaults standardUserDefaults] objectForKey:@ "appLanguage" ]] ofType:@ "lproj" ]] localizedStringForKey:(key) value:@ "" table: nil ] |
1 2 3 4 | if (![[ NSUserDefaults standardUserDefaults]objectForKey:AppLanguage]) { [[ NSUserDefaults standardUserDefaults] setObject:@ "zh-Hans" forKey:AppLanguage]; } label.text= CustomLocalizedString(@ "sub_menu_download" , nil ); //@"离线下载"; |
1 2 3 4 5 6 7 8 | NSString *currentLanguage = [[ NSUserDefaults standardUserDefaults]objectForKey:AppLanguage]; if ([currentLanguage isEqualToString: @ "en" ]) { [[ NSUserDefaults standardUserDefaults] setObject:@ "zh-Hans" forKey:AppLanguage]; } else { [[ NSUserDefaults standardUserDefaults] setObject:@ "en" forKey:AppLanguage]; } [[ NSUserDefaults standardUserDefaults] synchronize]; |