iOS swift代码里中文的国际化

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 的翻译了

最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容