swift NSLocalizedString in else if

swift NSLocalizedString in else if

我正在开发我的第一个 swift 应用程序。现在我想使用 NSLocalizedString 翻译 BUTTON 中的文本,但我不知道如何在 swift.

中编写它

这是我的 else-if 函数:

override func viewDidLoad() {
    super.viewDidLoad()
if volumeBool {
    volumeOut.setTitle("SOUND ON", forState: UIControlState.Normal)
} else {
    volumeOut.setTitle("SOUND OFF", forState: UIControlState.Normal)
}

感谢您的帮助。

使用

NSLocalizedString("string to translate", comment: "comment for the language file")

所以在你的 viewDidLoad:

override func viewDidLoad() {
    super.viewDidLoad()

    if volumeBool {
        volumeOut.setTitle(NSLocalizedString("SOUND ON", comment: "Title for sound on"), forState: UIControlState.Normal)
    } 
    else {
        volumeOut.setTitle(NSLocalizedString("SOUND OFF", comment: "Title for sound off"), forState: UIControlState.Normal)
    }
}