Search code examples
pythonurdu

Printing urdu (non-latin language) word by word using python


I am trying to print Urdu words using python. I read about Unicode but the [problem I face is that python tries to print the Urdu just like English, that is, from left to right and character by character. In Urdu characters] cannot be printed like those in English. I have already tried few solutions like the one mentioned here but they didn't work for me. I have been trying to print my Urdu string with the following code.

text_string = "آکاش کمار".decode('utf-8')   
print text_string

the output I get on Ubuntu terminal is like English from left to right instead of right to left and that too character by character.


Solution

  • I believe the problem is with Gnome Terminal which does not support bidirectional (i.e., right-to-left or "RTL") text output. If I run your above program (with an encoding declaration):

    # -*- coding: utf-8 -*-
    text_string = "آکاش کمار".decode('utf-8')
    print(text_string)
    

    in an Emacs shell buffer (with does support mixed LTR and RTL output), I get the correct output:

    $ python2 urdu.py
    آکاش کمار
    $ 
    

    However, if I run it in a Gnome Terminal, I get the backwards output that you posted.

    If you don't use Emacs, another alternative is to install the mlterm (multilingual terminal) package and use the terminal emulator it provides.