iOS APP 国际化(本地化)
2016-05-25 本文已影响0人
xygsz
一、目前,应用展示的所有文本都是以硬编码字符串存在于Main.storyboard 和 ViewController里。为了本地化这些字符串,你需要把它们放在一个单独的文件中。他将会在包中简单地引用这些字符串,而不是在你的方法中进行硬编码。Xcode使用带有 .strings 扩展名的文件来存储和检索app中使用的所有字符串,以支持每种语言。根据iOS 设备当前使用的语言,代码中一个简单的方法调用将会查找并返回要求的字符串。
二、创建Localizable.strings资源文件如下图:
![](https://img.haomeiwen.com/i1659266/d8ae00a0b0af003d.png)
![](https://img.haomeiwen.com/i1659266/07e213da2d9a6940.png)
三、选中刚刚创建的Localizable.strings文件,在右侧点击Localize...按钮,为其增加英语:
![](https://img.haomeiwen.com/i1659266/70aeb184dc50410c.png)
![](https://img.haomeiwen.com/i1659266/b67a0841b3ef5b01.png)
四、增加中文:
![](https://img.haomeiwen.com/i1659266/2bdf4a94fd029d8a.png)
![](https://img.haomeiwen.com/i1659266/2e0429820bfdaaa4.png)
![](https://img.haomeiwen.com/i1659266/6603094312a6e286.png)
![](https://img.haomeiwen.com/i1659266/88d76cd673d58226.png)
![](https://img.haomeiwen.com/i1659266/1201179bb201251d.png)
五、应用实例:
![](https://img.haomeiwen.com/i1659266/d6226f4aa3a8efc2.png)
![](https://img.haomeiwen.com/i1659266/6ff4d2c91a8af1cb.png)
![](https://img.haomeiwen.com/i1659266/2d4a45ac4f0730ea.png)