我的几个 SwiftUI 预览中有一堆字符串,但问题是它们包含在 Xcode Export Localizations 功能中。 有没有办法自动阻止
PreviewProvider
的字符串导出用于本地化?
我已经尝试将
PreviewProvider
结构包装在 #if DEBUG
中,但这不起作用。
Text(verbatim: "")
String("")
不过,以这种方式包装所有预览字符串确实很烦人。我不可能是唯一一个想要排除预览字符串的人,对吧?
x代码15.0.1
#预览 - 它会对你有帮助。
示例:
#Preview {
return VStack {
Button("Continue") {}.buttonStyle(MButtonStyle())
Button("Continue TB") {}.buttonStyle(TButtonStyle())
Button(action: { print("Button tapped")},
label: { Text("Custom Button").frame(maxWidth: .infinity) })
.buttonStyle(.borderedProminent)
.cornerRadius(30)
.tint(Color("mRed"))
Button("Custom Button") {
print("Button tapped")
}
.overlay( RoundedRectangle(cornerRadius: 30.0).stroke(lineWidth: 2.0))
.buttonStyle(FullWidthButtonStyle())
}
}
“Continue”、“Continue TB”等不会出现在可本地化字符串目录中