简体   繁体   English

使用python逐字打印乌尔都语(非拉丁语)

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

I am trying to print Urdu words using python.我正在尝试使用 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.我读过 Unicode,但 [我面临的问题是 python 试图像英语一样打印乌尔都语,即从左到右逐个字符地打印。 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.我在 Ubuntu 终端上得到的输出就像是从左到右的英语,而不是从右到左,而且也是一个字符一个字符。

I believe the problem is with Gnome Terminal which does not support bidirectional (ie, right-to-left or "RTL") text output.我相信问题在于 Gnome 终端,它不支持双向(即从右到左或“RTL”)文本输出。 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:在 Emacs shell 缓冲区中(确实支持混合 LTR 和 RTL 输出),我得到了正确的输出:

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

However, if I run it in a Gnome Terminal, I get the backwards output that you posted.但是,如果我在 Gnome 终端中运行它,我会得到您发布的反向输出。

If you don't use Emacs, another alternative is to install the mlterm (multilingual terminal) package and use the terminal emulator it provides.如果您不使用 Emacs,另一种选择是安装mlterm (多语言终端)包并使用它提供的终端模拟器。

通过使用 LibRaqm,您的问题可以解决,下面给出了该库的链接https://github.com/HOST-Oman/libraqm

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM