Swift:如何本地化计时器标签

时间:2022-06-19 05:40:05

I created a 4:00 minute countdown timer (NStimer). At the end of the countdown the figures change to letters, so instead of showing 0:00, it'll show DONE. I know how to localize buttons, but how do I localize this string, which is only visible in the function below? The string does not appear in the Main.strings. I want to translate it into several languages.

我创建了一个4:00分钟的倒数计时器(NStimer)。在倒计时结束时,数字会变为字母,因此不会显示0:00,而是显示DONE。我知道如何本地化按钮,但是如何本地化这个字符串,这只在下面的函数中可见?该字符串不会出现在Main.strings中。我想把它翻译成几种语言。

func stopTimer() {

    if count == 0 {
        timer.invalidate()
        timerRunning = false
        playSound()
        timerLabel.text = "DONE"

           }

1 个解决方案

#1


0  

I finally figured it out. I created this inside a function of my view controller:

我终于弄明白了。我在视图控制器的一个函数中创建了这个:

timerLabel.text = NSLocalizedString("DONE",comment:"end of countdown")

and then I added this to my localizable.strings of the source language

然后我将它添加到源语言的localizable.strings中

DONE="DONE";

and this in the localizable.strings of my target language

这在我的目标语言的localizable.strings中

DONE="ENDE";

I followed this tutorial, which I found more comprehensable.

我按照本教程,我发现更容易理解。

#1


0  

I finally figured it out. I created this inside a function of my view controller:

我终于弄明白了。我在视图控制器的一个函数中创建了这个:

timerLabel.text = NSLocalizedString("DONE",comment:"end of countdown")

and then I added this to my localizable.strings of the source language

然后我将它添加到源语言的localizable.strings中

DONE="DONE";

and this in the localizable.strings of my target language

这在我的目标语言的localizable.strings中

DONE="ENDE";

I followed this tutorial, which I found more comprehensable.

我按照本教程,我发现更容易理解。