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

cqoc49vn  于 2023-04-07  发布在  Swift
关注(0)|答案(1)|浏览(154)

在当前的XCode版本(14.3)中,本地化字符串不会在预览中显示,而是显示密钥。它们会在模拟器和设备上显示。有人能确认这种行为吗?或者我缺少了一个设置?
Localized.strings(de)示例:"price" = "Preis";
验证码:

Text("price")

预览 *:
价格
模拟器/器械:
普赖斯

  • )对于我正在使用的预览:
ContentView()
        .environment(\.locale, .init(identifier: "de"))

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

o4tp2gmn

o4tp2gmn1#

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

为您的字符串尝试此扩展

相关问题