SwiftUI - 本地化的辅助功能标签
我在 SwiftUI 中有以下代码,我想将辅助功能标签从英语翻译成波兰语:
Text("Example")
.accessibilityLabel("Color: \(color.description)")
我在 Localized.strings 文件中有这样的翻译:
/* Color: color.description */
"Color: %@" = "Kolor: %@";
/* Color */
"blue" = "niebieski";
我已经用 VoiceOver 对此进行了测试,它显示: “颜色:蓝色” 但应该读: “Kolor: niebieski”
这意味着 color.description (在我的例子中为“蓝色”)没有翻译为“niebieski”。这是为什么?我做错了什么?
I have the following code in SwiftUI and I want to translate accessibility label from English to Polish:
Text("Example")
.accessibilityLabel("Color: \(color.description)")
And I have such translations in Localizable.strings file:
/* Color: color.description */
"Color: %@" = "Kolor: %@";
/* Color */
"blue" = "niebieski";
I've tested this with VoiceOver and it reads:
"Kolor: blue"
But should read:
"Kolor: niebieski"
Which means that color.description ("blue" in my case) wasn't translated to "niebieski". Why is that? What am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该使用
NSLocalizedString
来本地化您的字符串。所以在你的情况下你应该使用
You should use the
NSLocalizedString
to localize your string.So In your case you should be using
我修好了:)这很简单。
这是一个工作代码:
如果颜色值来自变量(如原始问题中所示),则它将是:
重要的是使用 localizedString(value:)。
我已将accessibilityLabel 与accessibilityLabel 和accessibilityValue 分开。
I fixed it :) It's quite simple.
Here is a working code:
And if color value is from a variable (like in the original question), it will be:
What is important is to use localizedString(value:).
And I've separated accessibilityLabel to separate accessibilityLabel and accessibilityValue.