What's the correct writing in RightToLeft languages

This simple text: Text("10'20\"") when the localisation is a RightToLeft, like Arabic

on iMac show "20'10 on iOS show 10'20"

Which is the correct one?

Why the are different?

Accepted Reply

According to the Bidirectional Algorithm (http://www.unicode.org/reports/tr9/), for the text “10'20"”, when it is presented in a text element whose directionality is right-to-left or natural (with the UI Language set to Arabic/Hebrew), the two elements “10'” and “20"” will change visual positions compared to a left-to-right context, i.e. it will be what you say you’re seeing on iMac.

However, depending on what this text semantically conveys, the Bidirectional Algorithm can and should be overridden with markup with the use of characters like U+200E LEFT-TO-RIGHT MARK, U+200F RIGHT-TO-LEFT MARK and many others. You will notice that the outputs from many of the Formatter APIs include this markup to ensure that data is presented correctly.

To answer the question of why you’re specifically seeing a difference, we’ll need more details. I would suggest creating a sample project (or 2 projects, one for each platform) and filing a bug report via feedbackassistant.apple.com and mentioning the FB# here.

Replies

According to the Bidirectional Algorithm (http://www.unicode.org/reports/tr9/), for the text “10'20"”, when it is presented in a text element whose directionality is right-to-left or natural (with the UI Language set to Arabic/Hebrew), the two elements “10'” and “20"” will change visual positions compared to a left-to-right context, i.e. it will be what you say you’re seeing on iMac.

However, depending on what this text semantically conveys, the Bidirectional Algorithm can and should be overridden with markup with the use of characters like U+200E LEFT-TO-RIGHT MARK, U+200F RIGHT-TO-LEFT MARK and many others. You will notice that the outputs from many of the Formatter APIs include this markup to ensure that data is presented correctly.

To answer the question of why you’re specifically seeing a difference, we’ll need more details. I would suggest creating a sample project (or 2 projects, one for each platform) and filing a bug report via feedbackassistant.apple.com and mentioning the FB# here.

Thank you karanmisra for you explanation and interesting references. I'm going to improve my knowledge with unicode reports; anyway I filled a bug report.

  • Could you share the FB number with us here?

Add a Comment

Also FYI you may want to use ′ (Prime, U+2032) and ″ (Double Prime, U+2033) for correctness rather than quotation marks. These symbols are commonly used to represent a length (10 feet and 20 inches), an angular measurement (3° 5′ 30″), and minutes (10 minutes and 20 seconds). It is also used in Y′CbCr. Example usage:

let height = Measurement(value: 177, unit: UnitLength.centimeters)
height.formatted(
    .measurement(width: .narrow, usage: .personHeight, numberFormatStyle: .number.precision(.fractionLength(0)))
    .locale(Locale(identifier: "en_US"))
)
// 5′ 10″

Apple answer is:

"the behavior you experienced is currently functioning as intended.

The definition for NSWritingDirectionNatural has been different between AppKit & UIKit. With AppKit, the fallback direction for a content without any strong directionality is based on the primary localization. With UIKit, it’s LTR. We cannot change the behavior for AppKit since it requires a big amount of localization changes. If SwiftUI wants to use the UIKit behavior for AppKit, it should be using UIKit application context behavior."