support Arabic, Persian, ... strings

1,696 views
Skip to first unread message

Majid Mobini

unread,
Aug 30, 2014, 6:34:11 AM8/30/14
to kivy-...@googlegroups.com
Do you have any plan to support arabic like languages in kivy (Arabic, Persian, ...) ?

in text input, labels and etc.

ZenCODE

unread,
Aug 31, 2014, 1:02:47 AM8/31/14
to kivy-...@googlegroups.com
Kivy/Python is unicode capable, so supports any language. If it is not working for you, chances are you are just using a font that cannot display the characters you require? Otherwise, please post some example code showing your problem.

Peace

Majid Mobini

unread,
Aug 31, 2014, 2:19:16 AM8/31/14
to kivy-...@googlegroups.com
Hi

I have attached u my code, fonts, and output screenshot.
I'm using latest kivy in Windows.

Thanks.
main.py
scr2.png
scr1.png
arial.ttf
BNAZANIN.TTF

ZenCODE

unread,
Sep 3, 2014, 9:17:59 PM9/3/14
to kivy-...@googlegroups.com
Hi

Okay, so the screenshots seem to display Arabic, so what precisely is the problem? Is it when entering text that it does not display? Or is the the right-to-left issue?

You must please keep in mind we (speaking for myself) would have no idea whether what is displays is correct. So in order to test, it needs to be spelled out to us...;-)

Peace

Noman Mubasher

unread,
Sep 5, 2014, 12:20:41 PM9/5/14
to kivy-...@googlegroups.com
I have the same problem with Persian language, yeah it's showing the charchters but separated
It must come like this: سالم not س ا ل م

Mahdi Bornazadeh

unread,
Sep 6, 2014, 2:53:25 AM9/6/14
to kivy-...@googlegroups.com
for languages like arabic and persian we need right to left and reshape support
to change direction of text and the shape of charecters
and this feature is not supported in kivy.

for test purpose you can do it with arabic_reshape and python-bidi
but these work in python 2.x version only.

arabic_reshaper https://github.com/mpcabd/python-arabic-reshaper
python-bidi https://github.com/MeirKriheli/python-bidi

more info in my PR
https://github.com/kivy/kivy/pull/1739

sajad banooie

unread,
Sep 11, 2014, 8:02:18 AM9/11/14
to kivy-...@googlegroups.com
i have the same problem.
instead of سلام the out put is س ل ا م

sajad banooie

unread,
Sep 11, 2014, 8:30:01 AM9/11/14
to kivy-...@googlegroups.com
tnx my problem is fixed now
# -*- coding: utf-8 -*-

import kivy
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.uix.label import Label
import arabic_reshaper
from bidi.algorithm import get_display


class GUI(Widget):
    
    def __init__(self, **kwargs):
        super(GUI, self).__init__(**kwargs)

        label = Label(text=u"سلام", center=(100,100))
        label.font_name="BNAZANIN.TTF"
        label.font_size=40
        reshaped_text = arabic_reshaper.reshape(u'سلام')
        bidi_text = get_display(reshaped_text)
        label.text = reshaped_text = arabic_reshaper.reshape(bidi_text)
        self.add_widget(label)    

        
class MyApp(App):
    def build(self):
        return GUI()
    
if __name__ == '__main__' :
    MyApp().run() 
 
mr.mobini there is a way to apply this on  textinput class too:
class PersianTextInput(TextInput): def _create_line_label(self, text, hint=False): reshaped_text = arabic_reshaper.reshape(text) text = get_display(reshaped_text) super(PersianTextInput, self)._create_line_label(text, hint)
Reply all
Reply to author
Forward
0 new messages