psychopy.org | Reference | Downloads | Github

Align Arabic typed response - language style RTL/Arabic doesn't work in textboxes

What did you try to make it work?:
I’m trying to run an experiment using textbox with Arabic language which follows right to left language style. I still got the Arabic letters written from left to right even when I changed the style to Arabic and RTL style.

In the English version of the study I used the following codes for as follows:

in begin experiment tab I have:

inputText3 = ""

In begin experiment tab:

inputText3 = ""
actualKeys=""
shift_flag = False
event.clearEvents(‘keyboard’)

In each frame tab I have:

actualKeys = event.getKeys()
n = len(actualKeys)
i = 0
while i < n:
if actualKeys[i] == ‘return’:
continueRoutine = False
break
elif actualKeys[i] == ‘backspace’:
inputText3 = inputText3[:-1] # lose the final character
i = i + 1
elif actualKeys[i] == ‘space’:
inputText3 += ’ ’
i = i + 1
elif actualKeys[i] in [‘minus’, ‘-’, ‘num_subtract’, ‘Minus’, ‘slash’]:
inputText3 += ‘-’
i = i + 1
elif actualKeys[i] in [‘lshift’, ‘rshift’, ‘SHIFT’]:
shift_flag = True
i = i + 1
else:
if len(actualKeys[i]) == 1:
if shift_flag:
inputText3 += actualKeys[i].upper()
shift_flag = False
else:
inputText3 += actualKeys[i]
i = i + 1
In end routine tab:

thisExp.addData(“typedWord3”, inputText3)
inputText = ""

but these codes are not working at all in the Arabic version. I tried the text box and at least I got the Arabic letters displayed in the screen but in the wrong alignment (LTR).

I’m not sure if I need specific coding and whether or not there a way to make it using textbox?

Thank you
Ghozayel

Hi,
Python has a well known issue with Arabic. It can’t get the kerning right. The simplest work-around is to use a word processor to write the text you want to use as stimuli and convert them into images (just taking a screenshot will work if you don’t have access to a “cleaner” method). If you display them as images, they won’t be altered by Python’s text processing.
Good luck,
Mark

Hi Mark,

Thank you for your reply and suggestion. I’ve actually followed your suggested solution with the Arabic text I want to display on the screen, it works, thank you. However, I need to come up with a solution for text entries from participants, i.e. typing an Arabic script as a response to a question. I hope there’s a sort of trick that can make it happen :frowning:

Best,
Ghozayel