psychopy.org | Reference | Downloads | Github

Obtain written text in Hebrew/Japanese

Hi!

I have a little problem with translating my experiment to Japanese/Hebrew.

To obtain written text in English I added the following code component:
(Which still only allows me write lower-case, not upper-case letters…)

import string
allLetters = list(string.ascii_lowercase) + list(string.ascii_uppercase)

However, my main problem is that I dont understand how to change the code to obtain either Hebrew or Japanese characters?..

I realy hope someone can help!

Thank you in advance,
Nathalie

I’m not sure what the rest of your code is doing, but you can get other characters by their Unicode values (Unicode block - Wikipedia) - you can convert these from hex codes into integers like so:
int(value, 16)
And create a range() from the lowest value in a block to the highest. If you do chr(value) for each value in this range, it will give you each character in that block.

Hi There,

This demo might help. You can type responses in English or Hebrew. You would likely use a similar approach for your japanese characters.
typed-hebrew.psyexp (14.9 KB)

Hope this helps,
Becca

Dear Becca,

Thank you very much! This is very helpful :slight_smile:

I tried to adjust the eng_to_heb dictonary and add some unicodes of Japanese characters! I changed the unicodes of a and h (and they indeed give me Japanese characters - see below)!

However, Japanese should be written from left to right (as English). But he keeps writing both the Japanese and Hebrew characters from right to left (also if I turn of the reverse characters definition that you added - copied here below).

Is there a way to get Japanese (or in this case Hebrew) to be written from left to rigth?..

Thank you!
Nathalie

eng_to_jap = {“a”: “\u3041”, “b”: “\u05e0”, “c”: “\u05d1”, “d”: “\u05d2”, “e”: “\u05e7”, “f”: “\u05db”, “g”: “\u05e2”, “h”: “\u3043”, “i”: “\u05df”, “j”: “\u05d7”, “k”: “\u05dc”, “l”: “\u05da”, “m”: “\u05e6”, “n”: “\u05de”, “o”: “\u05dd”, “p”: “\u05e4”, “q”: “/”, “r”: “\u05e8”, “s”: “\u05d3”, “t”: “\u05d0”, “u”: “\u05d5”, “v”: “\u05d4”, “backslash”: “”, “w”: “’”, “x”: “\u05e1”, “y”: “\u05d8”, “return”: “”, “lctrl”: “”, “rctrl”: “”, “lshift”: “”, “rshift”: “”, “tab”: “”, “capslock”: “”, “lalt”: “”, “ralt”: “”, “quoteleft”: “”, “z”: “\u05d6”, “slash”: “.”, “comma”: “\u05ea”, “\u05ea”: “\u05ea”, “bracketright”: “”, “bracketleft”: “”, “equal”: “”, “minus”: “”, “semicolon”: “\u05e3”, “period”: “\u05e5”, “aspostrophe”: “,”, “space”: " ", “1”: “”, “2”: “”, “3”: “”, “4”: “”, “5”: “”, “6”: “”, “7”: “”, “8”: “”, “9”: “”, “0”: “”, “`”: “”};

function to reverse character strings

def reverse(text):
if len(text) <= 1:
return text
return reverse(text[1:]) + text[0]

In the code component in that file provided by Becca, you’ll see this in the “each frame” tab:

if expInfo['language'] == 'hebrew':
    hebrewString = ''
    for char in ans_String:# translate each character to the corresponding hebrew character
        hebrewString = eng_to_heb[char] + hebrewString

Try reversing the string concatenation, like this:

hebrewString = hebrewString + eng_to_heb[char]

Michael is absolutely correct! but only switch that for if the characters are Japanese (you still want your hebrew response to apear RTL )

Dear Becca/Micheal,

Thank you so much, it works! :slight_smile:
There is just one final thing that I dont succeed to fix.

When typing for example a semicolon (;), in Hebrew I should see the letter: “ף”.
Instead, it gives me all the hebrew letters that are inside the word “semicolon”. So, it writes: “דקצןבםךםמ”.

The same counts for bracketleft ([), bracketright (]) etc…

Is there a way to fix this?

Thank you!
Nathalie

Hi Nathalie,

Yes thanks for spotting that bug! This was happening because previously the translation was being read literally (i.e. the word ‘comma’ with each letter translates to hebrew, instead we needed to read each keypress individually).

This should fix that for you, here each key is watched and used to create the hebrew typed response.
typed-hebrew.psyexp (15.1 KB)

One funky thing someone highlighted to be here is that when the typed response is saved to your output file, The text is reversed LTR, even though it is written RTL onscreen. So, you may need to reverse ‘final_ans_String’ in the ‘end routine’ tab of the typeCode. That can be done using the python reverse() method Python List reverse() and is implemented in this example.

Hope this helps,

Becca

Hi Becca,

This worked perfectly!
Thank you very very much :slight_smile:

Nathalie

Hi That’s great - please could you mark the solution for future users :slight_smile:
Thanks,
Becca

Dear Becca,

I marked the solution! Thank you very much again.
I have however one other question (should I open another thread?)…

I dont succeed to display Japanese characters when reading from an excel file (Im attaching a relevant file). It just displays empty characters, instead of Japanese characters…

Hope you can help once more.

Thank you!
Nathalie

my_form_symp_female.xlsx (18.8 KB)