【发布时间】:2021-11-10 10:35:33
【问题描述】:
当我的 Text 从数组中获取它的字符串时,它不会本地化,但是当我硬编码它时,它会:
Localizable.strings
"greeting1" = "Hello there";
"greeting2" = "Howdy";
(本地化为英文)
我的看法
var localisedStrings = ["greeting1", "greeting2"]
struct Message: View {
var body: some View {
ForEach(localisedStrings, id: \.self) { string in
Text(string)
}
}
}
文本将只写键,例如 “greeting1”,而不是“Hello there”
有没有办法强制Text 对象使用本地化字符串?还是因为它从ForEach 循环中获取内容而发生了某种变化?
我的观点(硬编码)
//var localisedStrings = ["greeting1", "greeting2"]
struct Message: View {
var body: some View {
//ForEach(localisedStrings, id: \.self) { string in
Text("greeting1")
//}
}
}
这很好用,并导致文本显示“Hello there”。
【问题讨论】:
标签: swift foreach swiftui localization