Skip to content Skip to sidebar Skip to footer

Rtl Issue In String Containing English, Hebrew And Digits In Android (java)

I have an issue when mixing in one string English, Hebrew and digits. The order of digits next to Hebrew is getting reversed, no matter what order I make - fist digit and then text

Solution 1:

Nothing is screwing up here, this is actually correct behavior. The number is coming after the end of the hebrew word- the end of the hebrew word is on the left. What you seem to want is for the number to come before the hebrew word. But when you combine it with english like that it doesn't know tht the number is supposed to be bound to the hebrew part and not the english part, so putting it before the hebrew doesn't work either.

I'd suggest putting the number before the hebrew part and wrapping the number and hebrew text in unicode right to left mark characters, to tell it explicitly the 8 is part of the right to left text.

Alternatively you could put the number after the hebrew text but use an rtl mark before the hebrew and a ltr mark after. Which is probably a slightly better way of doing things overall if you want more complex embedding elsewhere.

Solution 2:

A tip for forcing English to be shown nicely when mixed with Hebrew:

Wrap the English (or numbers) words with LRI and PDI (check here: https://unicode.org/reports/tr9/ ) .

For example, instead of these (first word is in English) :

    <string name="test">ABC היא האפליקציה הכי טובה</string>
    <string name="test2">%1$s היא האפליקציה הכי טובה</string>

Use these:

    <string name="test">\u2066ABC\u2069 היא האפליקציה הכי טובה</string>
    <string name="test2">\u2066%1$s\u2069 היא האפליקציה הכי טובה</string>

Other useful ones can be found here:

https://stackoverflow.com/a/10989502/878126

Post a Comment for "Rtl Issue In String Containing English, Hebrew And Digits In Android (java)"