PDA

View Full Version : Translating problem (file loaded, but the strings isn't tranlated)



rsilva
20th April 2011, 04:39
I'm trying to translate my app and the only thing that i can translate is the Qt texts with loading "qt_pt.qm" but when I try to load my "app.qm" the text doesn't get translated.

I've tried everything i know, but it isn't working.

So, made another project and tried to translate words in Console App, same problem.

Can you help me ?

This is the .ts file:



<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.0" language="pt" sourcelanguage="en">
<context>
<name></name>
<message>
<source>old</source>
<translation>velho</translation>
</message>
<message>
<source>novo</source>
<translation>new</translation>
</message>
</context>
</TS>


This is my code:



#include <QtCore/QCoreApplication>
#include <QTranslator>
#include <QDebug>

int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);

QTranslator* tr = new QTranslator;
qDebug() << "loaded: " << tr->load("translator.qm", "C:\\C++\\Qt Projects\\Translator\\Translator");

qDebug() << "------------------";
qDebug() << QObject::tr("old");
qDebug() << QObject::tr("velho");
qDebug() << QObject::tr("new");
qDebug() << QObject::tr("novo");
qDebug() << "------------------";

a.installTranslator(tr);

qDebug() << "------------------";
qDebug() << QObject::tr("old");
qDebug() << QObject::tr("velho");
qDebug() << QObject::tr("new");
qDebug() << QObject::tr("novo");
qDebug() << "------------------";

return a.exec();
}


and I get this output:



loaded: true
------------------
"old"
"velho"
"new"
"novo"
------------------
------------------
"old"
"velho"
"new"
"novo"
------------------


It doesn't translate my text, link in my App, what I can do ?
What is wrong in the code ?
What I need to do to fix it ?

(Using Qt 4.7.2)

stampede
20th April 2011, 11:47
File name should not be a problem, change context name to QObject and it should work.
I've just tested your code and get this output:


loaded: true
------------------
"old"
"velho"
"new"
"novo"
------------------
------------------
"velho"
"velho"
"new"
"new"
------------------

.ts file:


<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.0" language="pt" sourcelanguage="en">
<context>
<name>QObject</name>
<message>
<source>old</source>
<translation>velho</translation>
</message>
<message>
<source>novo</source>
<translation>new</translation>
</message>
</context>
</TS>

Btw if you call lupdate <project file name> you will get proper file ready for translating. Don't forget to call lrelease <project file name> after editing the .ts file.

mcosta
20th April 2011, 11:53
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.0" language="pt" sourcelanguage="en">
<context>
<name>QObject</name>
<message>
<source>old</source>
<translation>velho</translation>
</message>
<message>
<source>novo</source>
<translation>new</translation>
</message>
</context>
</TS>

IMHO lines 11 and 12 are swapped. What you're saying is that the English WORD ("novo") has Portuguese translation ("new").

Have you written this file by hands or using QtLinguist??

rsilva
20th April 2011, 22:23
stampede

Thanks, it's worked, the context name was the problem ^^

mcosta

It's only for testing, this is why i've swapped the translations


Thank you two for awsering ^^