如何在 Swift 中将 NSLocalizedString 函数与变量一起使用? [英] How to use NSLocalizedString function with variables in Swift?

查看:54
本文介绍了如何在 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 this kind of stuff. Someone can explain me how to do that in Swift?

推荐答案

您可以在 NSLocalizedString 中使用 sprintf 格式参数,因此您的示例如下所示:

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 函数与变量一起使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆