带变量的NSLocalizedString对我不起作用

时间:2016-03-20 12:48:46

标签: string swift variables localization nslocalizedstring

所以我有以下代码:

GameScene:

Rule = Level / 10
let StrRule = String(Rule) //for example Level = 24 -> Rule = 2

let RegelString = String(format: NSLocalizedString("RegelText", comment: ""), StrRule)

//Give the String out in an UILabel as text
RegelLabel.text = RegelString

这就是我的Localizable.strings的样子:

"RegelText" = "You lose %d goals if you miss.";

所以我开始游戏,我的Level是24.所以Rule应该是2。

所以我建立并运行但是当我启动应用程序时,他向我展示了一些疯狂的数字。 标签就像:You lose 1314063968 goals if you miss.

为什么它不起作用?

1 个答案:

答案 0 :(得分:1)

StrRule代表数字。 %s显然不是一个数字。您打算使用RegelText吗? "RegelText" = "You lose %s goals if you miss."; 应该是这样的:

Rule

或者只使用Rule = Level / 10 let RegelString = String(format: NSLocalizedString("RegelText", comment: ""), Rule) 而不是将其转换为字符串。代码可能是这样的:

RegelText

在这种情况下,%d仍会使用Level / 10

此外,我没有看到您舍入Level / 10的结果。我知道将整数除以整数会产生整数,而不是小数。但为了安全起见,我认为你应该将round置于floor// app.js let foo = 3; let bar = 35; 函数中。

相关问题