小编Dio*_*uza的帖子

如何设置画布预览语言?

(目前正在 Xcode 11 Beta 7 上尝试)

\n\n

我想将已经本地化的字符串传递给 Text() 并使用“.environment(.locale, .init(identifier:"ja"))”查看它在画布上的外观,但预览始终设置为我选择的任何语言已设置方案设置。

\n\n

我知道如果我直接传递 LocalizedStringKey (如 Text("introTitle") ),它会起作用,但我不想这样做。相反,我想使用枚举,例如 Text(L10n.Intro.title),但是当我这样做时,环境运算符会被方案设置语言覆盖。

\n\n

这是错误还是预期行为?

\n\n
struct ContentView: View {\n    var body: some View {\n        Text("introTitle") //this works\n        Text(L10n.Intro.title) //this doesn\'t\n    }\n}\n\nstruct ContentView_Previews: PreviewProvider {\n    static var previews: some View {\n        ForEach(["en", "ja", "pt"], id: \\.self) { localeIdentifier in\n            ContentView()\n                .environment(\\.locale, .init(identifier: localeIdentifier)) //this gets ignored, and only the scheme settings language is previewed\n                .previewDisplayName(localeIdentifier)\n        }\n    }\n}\n\ninternal enum L10n {\n  internal enum Intro {\n    internal …
Run Code Online (Sandbox Code Playgroud)

xcode localization swift swiftui

5
推荐指数
1
解决办法
1167
查看次数

标签 统计

localization ×1

swift ×1

swiftui ×1

xcode ×1