本文介绍了带有swift变量的NSLocalizedString的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用NSLocalizedString本地化我的应用。当我导入XLIFF文件时,大多数工作就像一个魅力,但有些东西没有,一些字符串没有本地化。我注意到问题来自NSLocalizedString,里面包含一些变量,如:

I'm trying to localize my app using NSLocalizedString. When i import the XLIFF file, most works like a charm but something do not and some string is not localized. I have noticed that the problem is from NSLocalizedString containing something variable inside like:

NSLocalizedString(" - \(count) Notifica", comment: "sottotitolo prescrizione per le notifiche al singolare")

NSLocalizedString("Notifica per \(medicina!) della prescrizione \(prescription!)\nMemo: \(memoTextView.text)", comment: "Messaggio della Local Notification")

也许这不是这种东西的正确语法。有人可以解释我如何在swift中做到这一点?非常感谢。

Maybe this is not the correct syntax for thi kind of stuff. Some one can explain me how to do that in swift? Thank you very much.

推荐答案

您可以使用 sprintf 格式参数在 NSLocalizedString 中,所以你的例子看起来像这样:

You can use the sprintf format parameters within NSLocalizedString, so your example can look like this:

let myString = String(format: NSLocalizedString(" - %d Notifica", comment: "sottotitolo prescrizione per le notifiche al singolare"), count)

这篇关于带有swift变量的NSLocalizedString的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-15 13:04