Search code examples
androidtextunicoderight-to-left

is it possible to recognize in android/Java if a string text is written from Right to left?


I'm writing an android application, and i need to recognize if the text i have in a String is written in a language that is RTL(right to left) ? Thanks!


Solution

  • Two things:

    A/ http://pastebin.com/e276zn6y Javascript code to determine the script of a character. Should give you an idea. And with the help of:

    B/ ftp://unicode.org/Public/UNIDATA/extracted/DerivedBidiClass.txt

    # Bidi_Class=Right_To_Left
    0590          ; R # Cn       <reserved-0590>
    05BE          ; R # Pd       HEBREW PUNCTUATION MAQAF
    05C0          ; R # Po       HEBREW PUNCTUATION PASEQ
    05C3          ; R # Po       HEBREW PUNCTUATION SOF PASUQ
    05C6          ; R # Po       HEBREW PUNCTUATION NUN HAFUKHA
    05C8..05CF    ; R # Cn   [8] <reserved-05C8>..<reserved-05CF>
    05D0..05EA    ; R # Lo  [27] HEBREW LETTER ALEF..HEBREW LETTER TAV
    

    [...] truncated

    which gives you the direction of all blocks (showing the beginning to the RTL section), you can figure out the rest.

    EDIT: You might also want to check for Right-To-Left format characters (U+20xx), see http://www.unicode.org/charts/PDF/U2000.pdf