美文网首页
iOS swift代码里中文的国际化

iOS swift代码里中文的国际化

作者: zhangpengfic | 来源:发表于2019-07-27 17:01 被阅读0次

1,创建国际化标志。

NSLocalizedString构建标志,例如:"食物",print的"食物" 是国际化的字符串。

let food = NSLocalizedString("食物", comment: "这里注释写给翻译者...This string is shown when ...")

print(food)

label.text = food//某处使用了“食物”的字符串

2,制作翻译文件。

1,导出翻译文件。(以前翻译的内容会保留,这里只会增加新的source)

2,翻译文件是Hourse目录下所有文件,翻译的目标文件是en-AU 澳洲英文。

3,翻译。

1,导出的文件里新增加的source标签会含有“Food”的标志,

<file original="Hourse/zh-Hans.lproj/Localizable.strings" datatype="plaintext" source-language="zh-Hans" target-language="en-AU">    

<header>      <tool tool-id="com.apple.dt.xcode" tool-name="Xcode" tool-version="10.3" build-num="10G8"/>     </header>    

<body>      

<trans-unit id="食物">        

<source>食物</source>        

<note>这里注释写给翻译者...This string is shown when ...</note>      

</trans-unit>    

</body>  

</file>

2,增加target标签并翻译成澳洲英文

<body>     

<trans-unit id="食物">       

<source>食物</source>       

<target>food</target>       

<note>这里注释写给翻译者...This string is shown when ...</note>     

</trans-unit>   

</body>


4,翻译完成后导入。

5,运行项目切换成英文看效果。

print(food)//的结果就是了food

label.text = food//label上就显示food 的翻译了

相关文章

网友评论

      本文标题:iOS swift代码里中文的国际化

      本文链接:https://www.haomeiwen.com/subject/zpaqjttx.html