In my Xcode preview in a SwiftUI view, I'm testing different locales like this:
ForEach(["ar-SA", "tr-TR"], id: .self) { localIdentifier in
ContentView()
.environment(.locale, Locale(identifier: localIdentifier))
.previewDisplayName("Locale: (localIdentifier)")
}
However, for Arabic in my example, it's showing left-to-right when it should be the opposite. It seems I have to manually do something like this:
ForEach(["ar-SA", "tr-TR"], id: .self) { localIdentifier in
content
.environment(.locale, Locale(identifier: localIdentifier))
.modifier(if: localIdentifier.hasPrefix("ar-")) {
$0.environment(.layoutDirection, .rightToLeft)
}
.previewDisplayName("Locale: (localIdentifier)")
}
I thought the right-to-left should automatically be picked up from the locale. Is there something I'm missing so I don't have to explicitly set the layoutDirection
and automatically read from the supplied locale?
question from:
https://stackoverflow.com/questions/65623182/right-to-left-language-not-showing-in-xcode-preview-from-locale 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…