我在SwiftUI面临本地化问题。当翻译有占位符时,问题就会发生。我得到了错误“实例方法'appendInterpolation‘要求'LocalizedStringKey’符合'_FormatSpecifiable'"
代码
struct Translation {
struct school{
static var location: LocalizedStringKey {
return "schoolLocation %@"
}
}
}翻译文件
"schoolLocation %@“=”我的学校位置是%“;
SwiftUI视图
var location = "Some Name"
.navigationBarTitle("\(Translation.school.location) \(location)") 如果我做错了什么,请帮助我。
发布于 2020-09-06 09:01:28
您要做的是将一个已经用%@插入的字符串返回给一个内插字符串。因此,您生成的字符串如下所示:"schoolLocation %@ Some Name"。你可以这样做:
struct Translation {
struct school{
static func location(name: String): LocalizedStringKey {
return "schoolLocation \(name)"
}
}
}然后你可以像这样使用你的翻译:
var location = "Some Name"
.navigationBarTitle(Translation.school.location(name: location))https://stackoverflow.com/questions/63207339
复制相似问题