How to use NSLocalizedString

 

check your device supporting languages

 

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; 

NSArray *languages = [defaults objectForKey:@"AppleLanguages"]; 

NSLog(@"%@", languages);

 

 

set international for nib/xib file

 

1.nib/xib -> right click "Get Info"

2. Left click "Add Localization"

3. set the strings you need and save

 

 

Build Localizable.strings file

 

1.Resources -> right click and select "Add" -> "New File"

2. "Resource" -> choose "Strings File"

3. Save the file with name "Localizable.strings" or other name you like

4. Right click file "Localizable.strings"  -> choose "Get Info"

5. Left click "Make File Localizable" -> choose Tab "General"

6. Add "zh_CN" -> "Add" (or "zh_TW", "zh_HK" and so on)

 

Add souce code

NSString *testString = NSLocalizedString(@"title", nil);

The first param is key (title), the second param just a description, you can set it nil.

 

set Localizable.strings (English)

"title" = "my English title";

Be aware add semicolon at the end.

 

set Localizable.strings (zh)

"title" = "标题";

 

That's all.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值