Android Hebrew (RTL) Integration

我是研究僧i 提交于 2019-12-03 01:35:45

I think that Android's bidi analysis algorithm has some flaws. Unicode has two invisible, strongly directional characters that might help with these problems:

  • U+200E - left-to-right mark
  • U+200F - right-to-left mark

For the digit order problem, try putting left-to-right marks (U+200E) on both sides of the digit sequence.

Unicode also has the following bidi formatting codes:

  • U+202A - left-to-right embedding
  • U+202B - right-to-left embedding
  • U+202C - pop directional formatting (cancels the previous embedding or override)
  • U+202D - left-to-right override
  • U+202E - right-to-left override

For the problem with English fragments in Hebrew text, it might be as simple as putting a right-to-left mark before the English. (Android's algorithm may be under the impression that the paragraph is left-to-right since the first characters are English.) If that doesn't work, perhaps try surrounding selected text with some combination of formatting codes. (I'd try left-to-right embedding followed by pop directional formatting. I'd also try right-to-left embedding around everything combined with selective explicit right-to-left embeddings.)

The way these are supposed to affect text layout are defined by the Unicode Bidirectional Algorithm Unicode Standard Annex #9. However, if Android's implementation is broken (and I suspect it is), the best you can do is trial-and-error until you get things looking right. Good luck.

EDIT

As far as code is concerned, here's an example of how it might be done in Java:

String text = "גרסה \u200e2.100\u200e זמינה";

In XML, it might be:

<string name="update_available">גרסה &#x200e;2.100&#x200e; זמינה</string>

here is an example from my hebrew string xml, Thanks to Ted Hopp's answer:

you need to add '\u200e' before the char that causes you the problem:

<string name="basic_text1">המר על תוצאת המשחק\u200e:</string>

and the result will be:

 :המר על תוצאת המשחק
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!