Updated 2014-03-18 17:44:10 by Superlinux

Typing Arabic language in TK entry and text on starting from Mac OS X 10.9 plus starting from Windows Xp , is easy and comes out of the box, and without any interference from the programmers. However, on Linux this is not the case. The Arabic characters are put isolated and the words come in the reversed order. Therefore, I made the widget text to let the user type Arabic in a more readable way. This is still a starting point. I am soon going to develop it to make it better. Until now, Copying and pasting text to applications outside other Tk applications would make the Arabic reversed. tashkeel or Harakaat (حركات) are omitted . So, all you have to do here is start your application with this code.

However, When you want to save the text it will save the Arabic in the reverse order. I haven't tested printing on paper using this method but I am 90% sure that the Arabic will also be printed reversed.

bind Text <KeyRelease> {
 #Keys that must not modify the order of the letters
 set window_path "%W"
 set keys [list Arabic_comma Arabic_semicolon Arabic_question_mark ISO_Next_Group BackSpace Space Home End Tab CapsLock Delete F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12 KP_Enter Return Escape Up Right Down Left Win_R Win_L Pause Insert Alt_R Alt_L Shift_R Shift_L]
 if  { [lsearch $keys "%K"] > -1 } {

 set last_char [  $window_path get "insert-1 chars" ] ; #the last character is the one before insert cursor position
 set previous_to_last [  $window_path get "insert-2 chars" ] ; #the previous_to_last character is the one before insert cursor by two positions
 puts $last_char
 if { [regexp {[A-Za-z0-9]} $last_char ] ==1 } { return }
 set punctuations [list " " ؟  , < > ! ّ َ ً ِ ٍ ُ ٌ ْ"\t"]
 if { [lsearch $punctuations $last_char] > -1 } { 
  if { [regexp {[A-Za-z0-9.]} $previous_to_last ] !=1 } { 
     $window_path mark set insert "insert-1 chars" 

         $window_path mark set insert "insert-1 chars"
        set sub_word [  $window_path get "insert+1c" ] ; #the last ARABIC character

        puts "convert1 $sub_word"
        set sub_word [ string map {
        \u0628 \ufe91
        \u062A \ufe97
        \u062B \ufe9b
        \u062C \ufe9f
        \u062d \ufea3
        \u062e \ufeA7
        \u0633 \ufeb3
        \u0634 \ufeb7
        \u0635 \ufebb
        \u0636 \ufebf
        \u0637 \ufec3
        \u0638 \ufec7
        \u0639 \ufeCb
        \u063A \ufeCF
        \u0641 \ufeD3
        \u0642 \ufeD7
        \u0643 \ufeDb
        \u0644 \ufedf
        \u0645 \ufee3
        \u0646 \ufee7
        \u0647 \ufeeb
        \u064A \ufef3
        \u0626 \ufe8b
        } $sub_word] 
        if {$sub_word ==" " } { return }
         $window_path delete "insert+1c"
         $window_path insert "insert+1c" $sub_word

##The following is just a widget to for you to use it as a  test to the code above.
text .t
pack .t

[Category Arabic Language]