PDA

View Full Version : tr() does not translate utf-8 literals



Shark
30th June 2017, 15:53
Dear programmers,

in my Gui application (Qt version 4.8) I often use tr() to tanslate strings. It does work well with all string literals except those which contain utf-8 characters.

For example, such a line is


absChiSqrCheckBox = new QCheckBox(tr("\317\207\302\262 change <"));

So here we have the two utf-8 characters "χ²" (chi^2) encoded as octal C-characters.

In my qmake project file I have


CODECFORTR = UTF-8


And in main.cpp


QTextCodec::setCodecForTr(QTextCodec::codecForName ("UTF-8"));


I run lupdate, then the linguist and release the qm files.

So it seems I did exactly as is described in the Qt 4.8 documentation. I also tried trUtf8() instead of tr(), but this works neither. A string like the above is simply not translated.

Many thanks for answers!

Ginsengelf
5th July 2017, 08:13
Hi, can you add a translation for them in linguist? Or did lupdate mess it up already?

Ginsengelf

Shark
18th July 2017, 20:26
Hi, yes I could add the translation in the linguist. So, still I do not know the reason, but for the first release of my program I used a workaround:


chiSqrString = QString("\317\207\302\262");
absChiSqrCheckBox = new QCheckBox(QString(tr("%1 change <")).arg(chiSqrString));

thus avoiding a tr() on the utf string. Not so beautiful, but it's ok for the moment.