xcode:如何在代码中本地化字符串? [英] xcode: How to localize strings in code?

查看:73
本文介绍了xcode:如何在代码中本地化字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

本地化是指翻译成不同的语言. 我只找到了本地化故事板的说明,但是我也有一些在代码中设置的字符串. (我正在使用Swift)

With localize I mean translate into different languages. I only found Instructions for localizing the storyboard but I also have strings that I set in Code. (I'm using Swift)

推荐答案

简而言之—请参阅

In short — see the NSLocalizedString function. This is also there in Swift... its declaration looks like this:

func NSLocalizedString(
    key: String,
    tableName: String? = default,
    bundle: NSBundle = default,
    value: String = default,
    #comment: String) -> String

第三至第六个参数具有默认值,因此您可以这样称呼它:

The third through sixth arguments have default values, so you can call it like this:

NSLocalizedString("foo") // -> Maybe「フー」in your Japanese strings file?

或者像这样:

NSLocalizedString("foo", comment: "metasyntactic variable")

或带有其他参数组合.

查看《国际化和本地化指南》 在苹果的文档中.

这篇关于xcode:如何在代码中本地化字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆