SwiftUI: XCode预览不显示本地化字符串



在当前的XCode版本(14.3)中,本地化字符串不会在预览中显示,而是显示键。它们会在模拟器和设备上显示。有人能确认这个行为吗,还是我错过了一个设置?

的例子本地化。字符串(de):"price" = "Preis";

代码:

Text("price")

预览*:

价格模拟器/设备:
Preis

*)对于预览我使用:

ContentView()
.environment(.locale, .init(identifier: "de"))

如下所述:https://developer.apple.com/documentation/xcode/previewing-localizations

我得到了同样的问题,我通过清理构建文件夹来修复它。Command+Shift+K或通过菜单栏:Product ->Clean Build Folder

extension String {
func localized(with arg:[CVarArg] = [])->String{
return String(format:NSLocalizedString(self, comment:""), arguments: arg)
}
}

尝试这个扩展为您的字符串

最新更新