1.在Supporting Files文件夹右键,NewFile… -> iOS -> Resources -> String Files,命名为Localizable.strings
2.选中Localizable.strings 点击 XCode-> View-> Utilities -> File Inspector,在Localization中点+添加语言比如中文英文“test” = “test”;
和Localizable.strings(Chinese)就可以了
“test” = “测试”;
//获取当前的系统语言设置
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSArray *languages = [defaults objectForKey:@"AppleLanguages"];
NSString *currentLanguage = [languages objectAtIndex:0];
NSLog(@"%@",currentLanguage);
//设置用户语言为当前系统语言
[defaults setObject:currentLanguage forKey:@"user_lang_string"];
可以使用NSLocalizedString来调用。
UINavigationItem *navItem = [[UINavigationItem alloc]initWithTitle:NSLocalizedString(@"SignIn", @"Sign in now")];