1、在Resources下创建一个文件:Localizable.strings
2、在Localizable.strings的Get Info中选择Make File Localizable
3、切换至General标签页,并选择Add Localization
4、输入新的语系名称:zh_CN,并点击Add
5、在清单中你将看到两个文件:Localizable.strings(English)和Localizable.strings(zh_CN)
6、编辑Localizable.strings(English)
"title" = "This is English Version"; "string1" = "Apple"; "string2" = "Banana"; "string3" = "Orange"; "string4" = "Watermelon"; "string5" = "Strawberry";
7、编辑Localizable.strings(zh_CN)
"title" = "这是简体中文版"; "string1" = "苹果"; "string2" = "香蕉"; "string3" = "桔子"; "string4" = "西瓜"; "string5" = "草莓";
8、应用程序中加入以下代码:
- (void)viewDidLoad { [super viewDidLoad]; title.text = NSLocalizedString(@"title", nil); string1.text = NSLocalizedString(@"string1", nil); string2.text = NSLocalizedString(@"string2", nil); string3.text = NSLocalizedString(@"string3", nil); string4.text = NSLocalizedString(@"string4", nil); string5.text = NSLocalizedString(@"string5", nil); }
Interface Builder中的界面: