Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
415 views
in Technique[技术] by (71.8m points)

swiftui - Right-to-left language not showing in Xcode preview from locale

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...