本地化传递给视图的字符串
我正在尝试本地化传递给视图的一些文本,我有以下内容:
NavigationLink(destination: ManageConnectionsView(user: user).navigationBarTitle("", displayMode: .inline)) {
SettingsRowsView(systemName: "greetingcard", image: "", title: "Connections")
}
我想本地化 "Connections"
我尝试过:
NavigationLink(destination: ManageConnectionsView(user: user).navigationBarTitle("", displayMode: .inline)) {
SettingsRowsView(systemName: "greetingcard", image: "", title: LocalizedStringKey("Connections"))
}
但说: 无法将“LocalizedStringKey”类型的值转换为预期的参数类型“String”
在不创建额外变量的情况下执行此操作的正确方法是什么?
编辑:
我环顾四周发现了这个: String.localizedStringWithFormat(NSLocalizedString("Connections", comment: ""))
这是最新的解决方法还是有更简单的 SwiftUI 版本?
I'm trying to localize some text passed to a view, I have the following:
NavigationLink(destination: ManageConnectionsView(user: user).navigationBarTitle("", displayMode: .inline)) {
SettingsRowsView(systemName: "greetingcard", image: "", title: "Connections")
}
I want to localize "Connections"
I tried:
NavigationLink(destination: ManageConnectionsView(user: user).navigationBarTitle("", displayMode: .inline)) {
SettingsRowsView(systemName: "greetingcard", image: "", title: LocalizedStringKey("Connections"))
}
but says:Cannot convert value of type 'LocalizedStringKey' to expected argument type 'String'
What's the correct way of doing this without creating an extra variable?
Edit:
I found this looking around:String.localizedStringWithFormat(NSLocalizedString("Connections", comment: ""))
Is this the latest workaround or is there a simpler more SwiftUI version?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
更改
SettingsRowsView
以采用LocalizedStringKey
作为title
,而不是采用String
。Change
SettingsRowsView
to take aLocalizedStringKey
for thetitle
instead of taking aString
.