Swift NSLocalizedString不’;我不能在斯威夫特工作

Swift NSLocalizedString不’;我不能在斯威夫特工作,swift,localization,Swift,Localization,我对接口本地化字符串有以下问题: var friendsNumber = 3 var firstString = NSLocalizedString("I have 3 friends.", comment: "") // the translation works good var secondString = NSLocalizedString("I have \(friendsNumber) friends.", comment: "") // the translation doesn

我对接口本地化字符串有以下问题:

var friendsNumber = 3
var firstString = NSLocalizedString("I have 3 friends.", comment: "") // the translation works good

var secondString = NSLocalizedString("I have \(friendsNumber) friends.", comment: "") // the translation doesn’t work

我如何才能做到这一点?

在第二种情况下,您需要的是一个格式字符串

var messageFormat = NSLocalizedString("I have %d friends.", comment: "")
var message = String(format: messageFormat, friendsNumber)
然后在字符串文件中,您将得到:

中文:

"I have %d friends" = "I have %d friends";
西班牙文:

"I have %d friends" = "Tengo %d amigos";

等等。

@Sh_Khan我不知道你的意思。我的意思是“我有\(FriendsMember)friends.”如果工作,OP会忘记后挡板请参见我回答中的编辑原始照片OK,对于Int类型的te变量,它与%d一起工作,但是对于Double类型的变量,它不工作。