Qt Linguist: Encoding problem - QObject::tr doesn't translate sentences with accents
I'm using Qt 5.0.1 for my project, and I have translation issues. In my project, every source code is written in French, and I want to translate it in English. With the prior version of Qt (4.x), I used to translate my program with no problems. But now with Qt 5, sentences with accents are not translated anymore.
I know Qt5 expects the source code to be written with UTF-8. When I upgraded to Qt5, I changed the encoding of my files to UTF-8. So every header and source file is in UTF-8. I read on the Internet that one should add CODECFORTR = UTF-8 in their .pro file. Whether I do it or not, I still have the same issue.
Here is a piece of source code:
And here is how I see it in Qt Linguist:
We can notice that
[CODE]QAction *fSaveMass = file->addAction(tr("Enregistrer sous différentes teintes"));[/CODE]
has become in Qt Linguist
[CODE]QAction *fSaveMass = file->addAction(tr("Enregistrer sous diffÃ©rentes teintes"));[/CODE]
which means that Qt Linguist opens it thinking it's a latin encoding, while it's utf-8. But on the left and bottom side of Qt Linguist, it got the source code right: it's written "différentes" with the right encoding :s.
I think that's why my sentences with accents are not translated (the rest works fine). During my tests, I noticed that if I change the encoding back to the latin one I used before, without after launching lupdate nor lrelease, the text is properly translated in English. However if I switch off the translation, French accents are not properly rendered anymore :s
Has anyone got any idea? Maybe it has something to do with my compiler, which may not send the strings to QObject::tr with the right encoding or something similar. I use GCC 4.7.2, on Windows 8.
Thank you very much!
I solved the problem. I post here in case someone has the issue. It seems to be a glitch of QtLinguist. The only thing I was doing wrong was to release the qm files with Qt Linguist. If I release them with lrelease.exe, then it works as expected, sentences with accents are translated !
So don't release with Qt Linguist...