Why do these letters work in Linux and not Windows, and how do I fix it?

67 Views Asked by At

I'm working on translating a game made using Pygame/Pygame GUI into Norwegian, and it's been mostly working, except for the special letters! "æ", "ø", and "å" have been showing up as garbled gibberish, which essentially looks like AndvÃ╎rhÃ¥r

I asked for help from someone, and for them, they've been showing up just fine.

The only difference we can find is that my computer is Windows, and theirs is Linux! I essentially just want to know why this happens, and how I can fix it so it's an actually viable translation.

The coding in question:

if os.path.exists('resources/dicts/names/names.json'):
    with open('resources/dicts/names/names.json', encoding="utf-8") as read_file:
        names_dict = ujson.loads(read_file.read())

I tried setting the files to read it as utf-8, and I expected that to at least change how the file worked, and hopefully make it read the letters correctly. Instead, it did absolutely nothing. I then tried proofreading and redownloading the file after we found it worked for them, hoping it could have been a problem with how the files interacted in the old version, but that also did nothing.

UPDATE: So, now I feel rather silly. One of the solutions worked, and I'm not sure what did it, because I didn't notice until I made a new save just now. The old save had saved the names as the garbled letters, so I suppose problem solved?

1

There are 1 best solutions below

2
Tom McLean On

Have you checked that the text has been encoded as UTF-8 as well? By default, Python will use your systems default encoding when reading and writing from a file which is usually UTF-8, however on some machines it may be different.

This is PEP-686 https://peps.python.org/pep-0686/

You can check the systems default encoding using locale.getpreferredencoding(False)