Android Integration in Hebrew (RTL)

I am working on a relatively simple Android application. I want him to have an English version as well as a Hebrew version. (RTL Right to Left Alignment)

I manually changed the right alignment in the XML layout file. When the sentence contains numbers (in the middle), the numbers are displayed in mirror image: 29 is displayed as 92 , 21:45 appears as 54:12 , and 2000 is displayed as 000.2 .

In addition, when a sentence begins with numbers or English characters, they receive a throw until the end of the sentence that carried it all.

I think for version 4.0.3 for Android it supports Hebrew. I checked it in the emulator.

So, for older versions, is there a proper way to implement Hebrew? Please, help.

+6
source share
2 answers

I think Android bidi analysis algorithm has some disadvantages. Unicode has two invisible, highly directional characters that can help with these problems:

  • U + 200E - sign from left to right
  • U + 200F - sign from right to left

For a digit order problem, try placing the characters from left to right (U + 200E) on both sides of the digital sequence.

Unicode also has the following bidi formatting codes:

  • U + 202A - insert from left to right
  • U + 202B - insert from right to left
  • U + 202C - formatting the pop direction (cancels the previous attachment or redefinition)
  • U + 202D - redefinition from left to right
  • U + 202E - redefinition from right to left

For a problem with English fragments in Hebrew text, this can be as simple as putting a character from right to left in front of English. (The Android algorithm may be under the impression that the paragraph is left to right, since the first characters are English.) If this does not work, perhaps try to surround the selected text with some combination of formatting codes. (I would try nesting from left to right, followed by formatting the pop direction). I would also try to insert left to left everything that combined with selective explicit attachments from right to left.)

The way they should influence the layout of the text is determined by the bidirectional Unicode Unicode Standard Annex # 9 algorithm. However, if the Android implementation is broken (and I suspect it is), the best thing you can do is try a test error until you get the correct idea. Good luck.

EDIT

As for the code, here is an example of how this can be done in Java:

String text = "ื’ืจืกื” \u200e2.100\u200e ื–ืžื™ื ื”"; 

In XML, it could be:

 <string name="update_available">ื’ืจืกื” &#x200e;2.100&#x200e; ื–ืžื™ื ื”</string> 
+20
source

here is an example from my Jewish xml line, thanks to Ted Hopp:

you need to add '\ u200e' before the char, which is causing you a problem:

 <string name="basic_text1">ื”ืžืจ ืขืœ ืชื•ืฆืืช ื”ืžืฉื—ืง\u200e:</string> 

and the result will be:

  :ื”ืžืจ ืขืœ ืชื•ืฆืืช ื”ืžืฉื—ืง 
+2
source

Source: https://habr.com/ru/post/917755/


All Articles