在Xcode中,如何显示合并英语+阿拉伯语并以阿拉伯语开头的文本? [英] In Xcode, how to display text merging English+Arabic and beginning with Arabic?

查看:200
本文介绍了在Xcode中,如何显示合并英语+阿拉伯语并以阿拉伯语开头的文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将标签设置为字符串:خخخ刚购买:伪装套件。
但是当我运行测试时,标签显示.just buy:Disguise Kitخخخ?

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?

推荐答案

首先,阅读Cal Henderson的优秀了解双向(BIDI)文字Unicode。

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

信不信由你, UILabel 按照你提出的方式解决。你提供了一个从右到左的字符串(以阿拉伯语开头)。它开始显示从右到左。然后,您嵌入了一个从左到右排列的从左到右的英文字符串。然后它会看到这段时间,然后从右到左,因为这是一个阿拉伯字符串,恰好有一些英语(最好的 UILabel 可以告诉) 。

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).

你的意思是从左到右的字符串嵌入了阿拉伯语。这意味着你必须用从左到右的字符开始字符串。两个选项:在开头添加一些英语,或使用零宽度从左到右标记(U + 200E,LRM)将字符串的开头锚定到LTR模式。

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.

Objective-C:

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

Swift:

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

关于U + 200E的好消息是你可以在显示之前安全地将它添加到每个LTR字符串它。您甚至可以安全地将它放在LTR语言的本地化字符串的开头。如果它是多余的,它不会伤害任何东西。

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.

还有其他一些需要注意的事项:永远不要用ككك测试这些东西,总是用كتب测试(就像每个好学生一样) :D)或更好的东西,如الو。否则你无法判断阿拉伯语何时向后排列。我喜欢الو,因为它看起来非常不同。

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.

此外,在测试时,请注意Xcode不知道如何布局阿拉伯语。因此,如果您在代码中编写任何静态字符串,它们将在编辑器中向后显示,但它们将在UI中正确显示。让我疯狂。

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.

这篇关于在Xcode中,如何显示合并英语+阿拉伯语并以阿拉伯语开头的文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆