PDA

View Full Version : Problems with Qt Translations in Russian



ledams
21st July 2010, 17:30
Hi !

This is my first post on this forum, so l'll begin with a short introduction : I'm Damien, french programmer, and I currently have to maintain a Qt 3.3 application for Windows made by my company in 2005/2006. It was made for a specific client which wanted the application to be easily translatable.
This application works fine, is developed in french language, and an english translation is available since the end of the initial development. It was easily made with QLinguist, and works fine.

For your information, we are not creating the translation files ourselves, they are made by the client (which hires translators to make it). We have given him the QLinguist exec, with an empty ts file of the application so he can make as many translations as he needs.

Recently, he told us he was making a russian translation,and has warned us yesterday that a strange problem occurs when releasing the translation : 90% of the application is translated fine (dialogs, buttons, tooltips, etc.) BUT all the QActions (located in menus and toolbars) have their text replaced by a series of '?' characters. The number of '?' is apparently depending on the number of characters in the translation.
I have received his ru.ts and ru.qm files,and reproduced the phenomenon with my debug application (without any error message). The ts file seems to be OK in QLinguist or in a text editor like Notepad++, all the russain translations appear correctly.
I've developped a small tool which loads a qm file in a QTranslator, and displays all the messages in a QTable (with context, source, comments, translations, hash number, etc.), all translations appear and look fine. Everything seems OK, except that the qm file mainly contains empty contexts or source fields (despite that the corresponding translations appear correctly in dialogs for example).
the client told me he has built the ts file in QLinguist with copy/paste actions from an Excel 2003 sheet where the russian translator had written his texts.
If I replace the russian translation by the english one and release the qm file, the english translation works fine... The application main font is Arial. I've tried to force the defaultt codec for tr() to UTF8 without any change.

Do you have any idea of what's happening ?

You'll find the ts file in attachment.

Thanx for your help !
Regards !

ledams
23rd July 2010, 08:46
Hi again !

Seems that my problem did not really inspire you !;)
Nevertheless, I've worked a bit on it and found out the solution !

The problem was due to a double translation when constructing QAction with an action manager class :
In manager header, translatable strings were defined like this : myName = myClass::tr("Text");
In manager body, instead of being used like this : QAction(myName), they were used like that : QAction(tr(myName))

As tr() calls QApplication::translate() which takes a char * parameter for source string, the second call casts the translated QString in char * (using QApplication::DefautCodec (latin1)), the translation always fail, so the final QString displayed in application is a QString copy of the intermediate char *.
When destination language in written using Latin1 (like english), the char * cast remains correct with DefautCodec, and the final QString is readable.
When destination language in written with Unicode characters not included in Latin1 (like russian), the char * cast is not correct (so appears with ???????), and the final QString is a series of "??????" not readable.

Hope this may helps !

GreenScape
24th July 2010, 18:43
maybe this will help:
inside main:
...
QTextCodec::setCodecForCStrings(QTextCodec::codecF orName("windows-1251"));
...