psychopy.org | Reference | Downloads | Github

Including utf-8/unicode characters in online experiments

URL of experiment: https://pavlovia.org/run/jvcasillas/lextale_sp_template/html/

Description of the problem: I am preparing an online experiment in Spanish and have noticed that accented characters that work locally do not show up online. I have tried using the unicode characters, the dec and the hex, but nothing seems to work.

Hi @jvcasillas

The index.html file for running your experiments online should have page encoding <meta charset="utf-8">, which will include accented characters. I just tried running accented characters online from a text component, and this worked ok. Are you attempting to import accented characters from conditions file?

1 Like

Hi @dvbridges

I noticed that about the index.html file. I am, indeed, pulling words randomly from a conditions file and these words contain accented characters. Is there a workaround for this? I have also tried listing the words with u= beforehand to no avail.

For the time being I have just removed the accented characters. I opened a github issue here: https://github.com/psychopy/psychopy/issues/2299

and for the sake of completeness I will report back when this has a solution.

1 Like

I’m in a bit of a time crunch so I’m coming back to this one to see if anybody (@dvbridges perhaps) has any ideas for workarounds. Is it possible to force the encoding of item in list using something like u"?

Hi @jvcasillas, have you tried saving your csv so it is specifically compatible with UTF-8? When you “Save as”, try the web options in the tools menu next to the “Save” button. Go to the “encoding” tab and select “UTF-8” from the “save document as” drop down menu.

Not sure if that will work, but worth a try!

I hadn’t considered trying an excel file. I was using a .csv and saving with utf-8 encoding, but apparently that wasn’t working. I just passed the list to an excel file and the accented characters are now showing up as they should. Thank you, once again, for your insights. I will update the github issue as well.

1 Like

I had the same issue and the solution proposed in the GitHub Issue that @jvcasillas raised and referenced here solved it for me:

If you want to use Unicode characters in your online experiment and you use a .csv file for your conditions, make sure to save the conditions.csv file with UTF-8 encoding and BOM. If you, like me, create the conditions.csv file using pandas you can save your pandas data frame with encoding='utf-8-sig' (as discussed here), e.g., like this: df.to_csv('conditions.csv', encoding='utf-8-sig'. Worked perfectly in my case!