(目前正在 Xcode 11 Beta 7 上尝试)
\n\n我想将已经本地化的字符串传递给 Text() 并使用“.environment(.locale, .init(identifier:"ja"))”查看它在画布上的外观,但预览始终设置为我选择的任何语言已设置方案设置。
\n\n我知道如果我直接传递 LocalizedStringKey (如 Text("introTitle") ),它会起作用,但我不想这样做。相反,我想使用枚举,例如 Text(L10n.Intro.title),但是当我这样做时,环境运算符会被方案设置语言覆盖。
\n\n这是错误还是预期行为?
\n\nstruct 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)