nslocalizedstring和swiftui的价值
我正在尝试本地化具有内部值的文本视图而不会成功!
这是我通常要做的:
// ContentView.swift
Text("Tomato")
/* replaced by */
Text(NSLocalizedString("text-tomato", comment: ""))
// Localizable.strings (en)
"text-tomato" = "Tomato";
但是里面有一个值,我不知道该如何进行:
// ContentView.swift
Text("3 Tomatoes")
/* or */
Text("\(tomatoes.count) Tomatoes")
/* replaced by */
Text(NSLocalizedString("\(tomatoes.count) text-tomatoes", comment: ""))
// Localizable.strings (en)
"%@ text-tomatoes" = "%@ Tomatoes";
/* or maybe */
"(tomatoes.count) text-tomatoes" = "%@ Tomatoes";
/* or maybe */
"%@ text-tomatoes" = "(tomatoes.count) Tomatoes";
我尝试使用%@
,%lld
,值
等无成功。你有什么想法吗?
I'm trying to localize a Text view with a value inside without success!
Here's what I'm usually do:
// ContentView.swift
Text("Tomato")
/* replaced by */
Text(NSLocalizedString("text-tomato", comment: ""))
// Localizable.strings (en)
"text-tomato" = "Tomato";
But with a value inside I don't know how to proceed:
// ContentView.swift
Text("3 Tomatoes")
/* or */
Text("\(tomatoes.count) Tomatoes")
/* replaced by */
Text(NSLocalizedString("\(tomatoes.count) text-tomatoes", comment: ""))
// Localizable.strings (en)
"%@ text-tomatoes" = "%@ Tomatoes";
/* or maybe */
"(tomatoes.count) text-tomatoes" = "%@ Tomatoes";
/* or maybe */
"%@ text-tomatoes" = "(tomatoes.count) Tomatoes";
I have tried to use %@
, %lld
, value
, etc without success. Do you have any idea?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在发布我的问题之后,我终于找到了答案:
它像魅力一样工作!
其他示例: swiftui interpolation in swiftui
I have finally found an answer right after posting my question:
It's working like a charm!
Other example: Localization with String interpolation in SwiftUI
谢谢@alexxnd,
这对我有用:
“ TextfieldnotlallowedChar% @” - > “没有许可证角色'%@'”
我遇到了麻烦:
Thank you @Alexxnd
This is what worked for me:
"TextfieldNotAllowedChar %@" -> "No permitido el character '%@'"
I was having trouble with:
您不应使用swiftui使用
nslocalisterstring
,请使用常规text()
:不要忽略注释,它将在翻译过程中有助于上下文。
在准备本地化视图
You should not use
NSLocalisedString
with SwiftUI, use normalText()
:Do not ignore comments, it will help with context during translation.
Read more at Preparing views for localization