I’ve downloaded the Standalone PsychoPy 3.2.4 for MacOS. I’ve tried running an experiment involving words presented one word at a time in Arabic and the words appeared without diacritics although the excel document contains the list of words with diacritics. Is there a way to make diacritical marks appear on Arabic words? Thanks.
Hi,
- Would you mind posting a minimal reproducible example here, plus screenshots of what the current output is and what you would like it to be?
- If you switch to the Coder view and from the Demos menu, run the Stimuli -> textStimuli.py script, do the diacritics appear properly there?
- I’m going to guess that this is likely going to just be a font issue. What happens if you try other fonts for the text stimulus?
Caveat: I can’t read Arabic at all, but with a bit of hand-holding was able to solve issues with displaying re-shaped and bi-directional Arabic text.
the markings on top of the letters are missing as you can see in the screenshots
OK thanks, could you please post a spreadsheet here (only a couple of representative rows needed)?
book.xlsx (8.6 KB)
Thanks. The problem seems to be pretty deep-rooted, and at this stage seems to lie outside of PsychoPy’s own code base, and instead be an issue for the third-party drawing systems that we rely upon to display text.
I’ll look into it a bit further… Unfortunately there is not much online about other people dealing this issue, even though it must be much wider-spread than just the PsychoPy project, and be a general Python issue.
Hi, sorry this took a while but the answer was staring at me all the time. We are going to need to make some changes to PsychoPy for a future release to get this to work automatically.
But in the interim, we may be able to get things working for you immediately by using some custom code. Let me know if you’d like to go further with this, or if this is too late a response to be useful.
yes sure, I would like to use custom code. Thanks
Hello Sir,
@Michael I am using an Arabic self-paced reading task, but still I can’t find a way to put the diacritic marks on the Arabic words. Could you please advise if any changes has been made to PsychoPy to make this feature appear during the task?
Thank you in advance.
A
What font are you using?
I am using Arial.
[Ignore the previous version of this post, example text has been provided earlier in this thread.]
I’m sorry, I must have made some insight into this issue but never followed through on it. Now unfortunately I can’t remember what that insight was. Will try to look further into it, but from what the past version of myself seemed to be saying, there should be a solution to this that we can implement.
Thank you. Would very much appreciate your help and advice on this issue.
Ala’a
Thanks for your patience. So I used the examples provided by @Shorouq_H above:
and tried out a script which would alter PsychoPy’s behaviour to preserve the harakat when reshaping and preparing the script for right-to-left display. Here are the results:
This is using the open source Sahel font, which is available freely. Unfortunately, not many fonts work well in PsychoPy when displaying Arabic with diacritics - the only others I found to work on my Mac were Arial Unicode MS
and Tahoma
.
Five others looked mostly OK but but showed some glitches with some of the diacritics: Arial
, Microsoft Sans Serif
, Nadeem
, Noto Sans Arabic
, and Times New Roman
.
So what I need to do from here is make some changes to the PsychoPy source code and issue a pull request so that it can be incorporated in a subsequent release. That may take quite some time to become available to regular users.
If you need this available relatively quickly, let me know, and I’ll show how you could add some custom code to your experiment to get this working for you right away.
Hi Micheal,
Rather, thank you so much for the updates on PsychoPy to display ‘harakat’ over of the Arabic alphabetical characters. I tried the suggested fonts on my Mac, but unfortunately the diacritics are not showing. Further, in some fonts (e.g., Unicode MS, Sahel and Noto Sans Arabic) the characters were not connected. It might be something with my Mac. I am not sure, specially that Sahel font worked really fine with you.
I would very much appreciate it if you could show me a custom mode that works with the Arabic diacritics, please.
Thank you so much.
Ala’a
It looks like you are doing some sort of self-paced presentation of text, masking some characters? I’ll assume that you have some variable called, say, my_text
that contains the current text string to display.
So insert a Text component set to the default language style i.e. LTR
rather than RTL
or Arabic
(because your custom code will be doing the text processing and we don’t want the text component to interfere with that).
Then insert a Code component. In its “Begin experiment” tab, put something like this:
from bidi.algorithm import get_display
from arabic_reshaper import ArabicReshaper
# configuration which will retain diacritics but also shift
# them by 1 position to work with the bidi algorithm:
arabic_configuration = {'delete_harakat': False,
'shift_harakat_position': True }
reshaper = ArabicReshaper(configuration = arabic_configuration)
Then in, say, the “Begin routine” tab, put something like this:
# ensure characters link to each other properly, retaining but shifting
# diacritics:
processed_text = reshaper.reshape(my_text)
# apply the bi-directional algorithm to reverse text for displaying RTL:
processed_text = get_display(processed_text)
# update the stimulus:
your_text_stimulus.text = processed_text
Please do try the Sahel
font again with this solution - the issues you saw may have been due to the reshaping and bidirectional processing not being applied properly. Even if the code above is working, the output will not look correct unless the right font is used.
[Note to future readers: a pull request to address this behaviour has been submitted, so in an upcoming PsychoPy release, diacritic marks in Arabic text should automatically be retained:]
Hi Micheal,
Thank you so much for the code. I added it to the experiment, but I don’t exactly know what went wrong and caused the sentence not to show when I run the experiment.
trial_1.psyexp (11.6 KB)
I can’t run that without the accompanying conditions file (Stims.xlsx
).
But even without seeing that, my question is where do you define the variable my_text
? As in the post above:
If you don’t have a variable called that, the code simply can’t work. You can replace it of course with your own relevant variable name. I see your conditions file has a variable called S1
. Does that contain the text you want to display?
If so, simply replace the variable name my_text
in the code I gave above with your actual variable name, S1
.
NB you are also trying to update the text component via the graphical interface, by putting $'S1'
in the text field and setting it to update every repeat.
That won’t work for several reasons. Firstly you are putting quotes around S1
, so that will print the literal letters 'S1'
, and not the contents of the variable called S1
. Secondly, by setting it to update every repeat, and putting it after the code component, you will be undoing whatever the code component does. Don’t try both approaches at the same time: we are updating the text field in code, not via the component settings.
So just put some junk text in that text field (like 12345
) and set it to be “constant” rather than to “set every repeat”. That way you won’t be fighting against the custom code, and if 12345
gets shown, you’ll know that the code isn’t working somehow.
Hi Michael,
I would like to express my gratitudes to @Michael for providing the code needed to display the diacritics on the Arabic alphabetical characters.
I tried different fonts till I was able and lucky to find the suitable one (at least on my Mac). However, I still have one issue that I was not able to solve. That is, the Arabic sentence on the screen starts from the bottom line. Would you please help to solve this issue, please?
I am providing the conditions file and the psyexp file.
loopTemplate.xlsx (17.8 KB)
Trial1.psyexp (11.4 KB)
Thank you in advance.
Ala’a