本文介绍了带变量Swift的NSLocalizedString的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图弄清楚如何将NSLocalizedString与变量一起使用.
I'm trying to figure out how to use NSLocalizedString with variables.
例如,如果我想在我的Localizable.strings
文件中输出"by Peter and Larry",我应该具有以下内容吗?
For example, if I want to output "by Peter and Larry", in my Localizable.strings
file, should I have the following?
"account.by_user" = "by %@ and %@";
如果有两个变量name1
和name2
,其中name1
= Peter和name2
= Larry,我该如何调用NSLocalizedString("account.by_user", comment: "")
?
How would I call NSLocalizedString("account.by_user", comment: "")
with if there are 2 variables name1
and name2
where name1
= Peter and name2
= Larry?
推荐答案
是的,您应该拥有"account.by_user" = "by %@ and %@";
并接受:
yes, you should have "account.by_user" = "by %@ and %@";
and take this:
let localizedString = NSLocalizedString("account.by_user", comment: "any comment")
let wantedString = String(format: localizedString, "Peter","Larry")
这篇关于带变量Swift的NSLocalizedString的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!