2

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.

  • That's because your terminal doesn't use a proper text layout engine. – Ignacio Vazquez-Abrams Oct 01 '17 at 06:16
  • That a problem of the terminal application, more exactly it should print the command prompt LTR and your output RTL. That would result in a large mess especially when both has go in one line. So usually there can be only one direction. – Klaus D. Oct 01 '17 at 06:20

2 Answers2

2

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.

K. A. Buhr
  • 45,621
  • 3
  • 45
  • 71
  • Thanks for the help but the real goal that I was trying to achieve using this thing was to generate images that contain the Urdu text for training a text/non-text Urdu classifier. I followed the same code but instead of printing the output I tried to draw it on a image but I still got the similar issue. – Nilesh Kumar Oct 01 '17 at 15:15
  • @NileshKumar: *Again*, layout engine. Use one. – Ignacio Vazquez-Abrams Oct 02 '17 at 18:00
0

by using LibRaqm your problem can be solved the link to the library is given below https://github.com/HOST-Oman/libraqm