In Xcode, how to display text merging English+Arabic and beginning with Arabic?

arabic localization in ios swift
rtl in swift
bidirectional text

I want to set a label to string: "خخخ just bought: Disguise Kit." but when I run the test, the label show ".just bought: Disguise Kit خخخ"?

If the text is not begin with Arabic, It will show as what I set. What's the problem?

Does anybody know how to deal with this issue?

First, read Cal Henderson's excellent "Understanding Bidirectional (BIDI) Text in Unicode.".

Believe it or not, UILabel is laying it out the way you asked. You've provided a right-to-left string (starting in Arabic). It starts displaying that right to left. You then embedded a left-to-right English string, which it lays out left to right. It then sees the period, and lays that out right-to-left since this is an Arabic string that just happens to have some English in it (as best UILabel can tell).

What you meant to have is a left-to-right string with Arabic embedded. That means you have to start the string with left-to-right characters. Two options: add some English to the start, or use the zero-width Left-to-Right Mark (U+200E, LRM) to anchor the beginning of the string into LTR mode.


self.label.text = @"\u200eكتب just bought: Disguise Kit.";


self.label.text = "\u{200E}كتب just bought: Disguise Kit."

The good news about U+200E is that you can safely add it to every LTR string before you display it. You can even safely put it at the start of your localized strings for LTR languages. If it's redundant, it doesn't hurt anything.

A couple of other things to note: never test this stuff with ككك, always test with كتب (like every good student :D) or better yet something like الو. Otherwise you can't tell when the Arabic is laid out backwards. I like الو because it looks wildly different backwards.

Also, when testing, note that Xcode doesn't know how to layout Arabic. So if you write any static strings in your code, they'll be displayed backwards in the editor, but they'll display correctly in the UI. Drives me crazy.

In Xcode, how to display text merging English+Arabic and , In Xcode, how to display text merging English+Arabic and beginning with Arabic? 由女生的网名这么多〃 提交于2019-12-03 03:20:09� For an app localized in both English and Spanish, the above view displays “pencil” and “lápiz” for English and Spanish users, respectively. If the view can’t perform localization, it displays the key instead. For example, if the same app lacks Danish localization, the view displays “pencil” for users in that locale.

Since iOS 10 (and macOS 10.12) String localizedStringWithFormat inserts Unicode isolates around placeholders. This is a higher level way to format strings with mixed language direction, without manually inserting directional marks.

String.localizedStringWithFormat("%@ just bought: Disguise Kit.", "خخخ")
// "⁨خخخ⁩ just bought: Disguise Kit."

Compare to:

String(format: "%@ just bought: Disguise Kit.", "خخخ")
// ".just bought: Disguise Kit خخخ"

To see what localizedStringWithFormat is doing:

let scalars = String.localizedStringWithFormat("%@ just bought: Disguise Kit.", "خخخ") { "U+\(String(format: "%04X", $0.value))" }
// ["U+2068", "U+062E", "U+062E", "U+062E", "U+2069", "U+0020", ...

Where U+2068 is FIRST STRONG ISOLATE, and U+2069 is POP DIRECTIONAL ISOLATE. You can read more about isolates in:

This feature was introduced in WWDC 2016 session 232 What's New in International User Interfaces

Text is not set to right while select arabic language from app � Issue , Text is not set to right while select arabic language from app #109. Closed forceRightToLeft when I change to arabic from english but issue is not solved. The PR from @Mehrdadmaskull is merged and was released as part of 3.1.0. I don't exactly remember the details of iOS localization anymore. The Video above techies you how to change a label's text when a button is clicked; Enjoy! Website - Email me - Please Subscribe! Rate and Comment!

Actually, \u{200E} (or any) symbol can be inserted into the string literal.

  1. Add "Unicode Hex Input" (System Preferences -> Keyboard -> Input Sources -> + -> Unicode Hex Input).
  2. In the text editor move the cursor to the place where you want to insert a symbol.
  3. Switch input source to the "Unicode Hex Input".
  4. Hold the Option key and type 200E.
  5. The symbol should be inserted and the string should look like you expect.

How do you "add" two text fields?, displayed in the label, but i want to display the content of both of the textfields. @IBAction func buttonPushed(sender: UIButton) { Label.text about them, Apple's own book on Swift being the best place to start, I believe. Element == String { var concatenation: String {return reduce("", combine: +)} } [textfield1, textfield2]. Creates a dictionary by merging key-value pairs in a sequence into the dictionary, using a combining closure to determine the value for duplicate keys. func reserve Capacity (Int) Reserves enough space to store the specified number of key-value pairs.

Localizing Your App, Searching Strings � Sorting Strings � Displaying Text � Parsing Text The next time you import localizations, the strings files are merged When you export localizations, Xcode includes an InfoPlist.strings file for translation. In this Xcode tutorial I will be showing you how change the text which appears in a UILabel programmatically rather than via using the Interface Builder in Xcode 4.

Supporting VoiceOver in Your App, In a few steps you can make your app VoiceOver accessible in Xcode or programmatically. For example, in English-speaking countries, VoiceOver reads from left-to-right, while If you vertically stack labels in a UI or display text in a table, VoiceOver may not read the For example, group to combine the labels as follows:. In Xcode, how to display text merging English+Arabic and beginning with Arabic First, read Cal Henderson's excellent "Understanding Bidirectional (BIDI) Text in Unicode.". Believe it or not, UILabel is laying it out the way you asked.

iOS i18n: Internationalizing Storyboards in XCode – The Phrase , Detractors often mention merge conflicts in teams, slow load times, and having to maintain Notice that XCode added the English text as the source automatically. Check out this ugly truncation in our plant details screen. This tutorial will show you how to read basic text from files uploaded to the web and how to display this text in an application. Download the Source Code: h

  • Is this a RTL problem? Can you encourage the arabic to display LTR?
  • @JamesWebster I don't think so. if it is RTL problem, why just for this case which begin with Arabic word?
  • Because the sentence will begin RTL, (خخخ starts right heading left), then it appears to swap to LTR to draw the remaining words.
  • @JamesWebster Could you give an example how to fix? Because if you set Label.textAlignment = UITextAlignmentRight; it is just show the text right align, instead of revert the string order.
  • I'm afraid I don't know how to fix it. I just recognised that it might be this problem. I haven't really worked with RTL languages.
  • Thanks so much, that's what I want!
  • I had to use \U200E (capital U and E) for it to work in Obj-C from a Localizable.strings file
  • Is there zero-width Right-to-Left Mark?
  • Thanks. localizedStringWithFormat worked liks charm.