I'm trying to use Kivy's text input for Arabic text. I have an Arabic font set up with my text input but when I type into the input (in Arabic) I just get Arabic letters appearing from left to right (and they're not connected as Arabic letters should be when they're adjacent to each other).
Is there a way to get Kivy/text input to support RTL languages input that I'm missing (esp Arabic).
Here's my code,
from kivy.app import App
from kivy.uix.floatlayout import FloatLayout
Config.set('graphics', 'width', '300')
Config.set('graphics', 'height', '500')
logger = logging.getLogger('')
from kivy.uix.textinput import TextInput
class EditorApp(App):
def build(self):
f = FloatLayout()
textinput = TextInput(text='Hello world', font_name='DroidKufi-Regular.ttf')
# import pdb; pdb.set_trace()
f.add_widget(textinput)
return f
if __name__ == '__main__':
EditorApp().run()
The result of this code:
Unfortunately, Kivy TextInput support for right-to-left is an open issue (checked 29/05/2015). Actually, Kivy is not supporting right-to-left not only to TextInput.
For static texts like labels , there is a hack by using arabic_reshaper and python-bidi (reference):
import arabic_reshaper
from bidi.algorithm import get_display
reshaped_text = arabic_reshaper.reshape(u'اللغة العربية رائعة')
bidi_text = get_display(reshaped_text)
Yet, as for TextInput
with a dynamic input, you had to override most of class methods to support RTL and you will end up like implementing the whole RTL support to kivy.
Here is an open attempt to implement Kivy bidi support. Another closed one: Right-to-left labels support.