开发者

Qt Translation lupdate and namespaces

开发者 https://www.devze.com 2022-12-19 19:47 出处:网络
While developing a Qt Application, I ran into a problem in using QTranslator. After a little research, I found out that the problem was with lupdate from Qt having problem with the

While developing a Qt Application, I ran into a problem in using QTranslator. After a little research, I found out that the problem was with lupdate from Qt having problem with the

using namespace;

directive. Following the instructions found in here, I discovered that I have to use special comments in my code, to help lupdate understand that the classes are inside a namespace. The special comment is something like开发者_Go百科 this:

 /*
 TRANSLATOR namespace::MyClass
 */

So, I added this comments in all my sources that had QStrings being managed by tr. But, still, the applications is not being translated. The installTranslator method of QTranslator is returning true. The actual code I'm using to install the Translator is

Application app(argc,argv); //Application is a subclass of QApplication
QTextCoded::setCodecForTr(QTextCodec::codecForName("utf8"));
QTranslator translator;
translator.load(QString("..//language//") + locale);
app.installTranslator(&translator);
app.exec();

Have anyone ran into the same problem? What am I doing wrong?

EDIT--

Corrected one little mistake in the code above, but still no results.


You do install the translator but do not load any translation for it.

The documentation you link to specifies exactly:

int main(int argc, char *argv[])
{
     QApplication app(argc, argv);

     QTranslator translator;
     translator.load(QString("arrowpad_") + locale); // here load translation
     app.installTranslator(&translator);

     app.exec()
}
0

精彩评论

暂无评论...
验证码 换一张
取 消