我正在尝试添加带有参数的 SwiftUI 本地化文本。然而,在整个应用程序中,我们使用本地化键的包装器,所以我们有这样的东西:
static let helloWorldText = NSLocalizedString("helloWorldText", comment: "")
随着使用
label.text = LocalizationWrapper.helloWorldText
or
Text(LocalizationWrapper.helloWorldText)
而且效果很好。
然后,当涉及到添加带有参数的本地化文本时,它似乎不起作用。
所以我有一把钥匙"helloWorld %@"
我有一个static let helloWorldWithParameter = NSLocalizedString("helloWorld %@", comment: "")
现在我尝试这样做:
Text("\(LocalizationWrapper.helloWorldWithParameter) \(name)")
Text(LocalizedStringKey(LocalizationWrapper.helloWorldWithParameter + " " + name))
Text(LocalizationWrapper.helloWorldWithParameter + " " + name)
然而它们都不起作用Text("helloWorld \(name)")
工作得很好。
然后我尝试删除 NSLocalizedString 只留下LocalizationWrapper.helloWorldWithParameter
作为一个干净的字符串,但它什么也没做
我怎样才能做到这一点?我看到THIS https://stackoverflow.com/questions/62168292/what-s-the-equivalent-to-string-localizedstringwithformat-for-swiftuis-lo但它有点脏。