Translating problem (file loaded, but the strings isn't tranlated)
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:
Code:
<?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:
Code:
#include <QtCore/QCoreApplication>
#include <QTranslator>
#include <QDebug>
int main(int argc, char *argv[])
{
qDebug() << "loaded: " << tr->load("translator.qm", "C:\\C++\\Qt Projects\\Translator\\Translator");
qDebug() << "------------------";
qDebug() << "------------------";
a.installTranslator(tr);
qDebug() << "------------------";
qDebug() << "------------------";
return a.exec();
}
and I get this output:
Code:
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)
Re: Translating problem (file loaded, but the strings isn't tranlated)
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:
Quote:
loaded: true
------------------
"old"
"velho"
"new"
"novo"
------------------
------------------
"velho"
"velho"
"new"
"new"
------------------
.ts file:
Code:
<?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.
Re: Translating problem (file loaded, but the strings isn't tranlated)
Code:
<?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??
Re: Translating problem (file loaded, but the strings isn't tranlated)
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 ^^