PDA

View Full Version : Use Translation file



ruben.rodrigues
17th May 2011, 17:25
Hi all!

I just start reading how to use the translator file and the QTranslator and I need some help to see if what I am doing is any close.

the ts file

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.0" language="de" sourcelanguage="en">
<context>
<name>QObject</name>
<message>
<source>Username</source>
<translation>Benutzername</translation>
</message>
<message>
<source>Password</source>
<translation>Passwort</translation>
</message>
</context>
</TS>


Contructor of my class

QString german = "C:/esp/lang/deutsch.ts"; QTranslator_Language.load(german);
QCoreApplication::installTranslator(&_Language);
ui.label->setText("Username");
ui.label_2->setText("Password");

I was expecting that the Username would be translated to "Benutzername" and Password to "Passwort".

I also tried _Language.translate function but didn't work.

mcosta
17th May 2011, 19:07
To use Translator you have to "wrap" visible strings.



QString german = "C:/esp/lang/deutsch.ts";
QTranslator _Language.load(german);
QCoreApplication::installTranslator(&_Language);
ui.label->setText(tr("Username"));
ui.label_2->setText(tr("Password"));

ruben.rodrigues
18th May 2011, 11:54
Hi again.

I just noticed that there is something wrong with the load command, as it return false..

I also switch to ubuntu because there is where I fell more comfortable working with qt.

my constructor has this:

QTranslator Lang;

if(Lang.load("/esp/Lang/de.ts")){

cout << "Loaded" << endl;

QCoreApplication::installTranslator(&Lang);

cout << QString(tr("Username")).toStdString() << endl;
cout << QString(tr("Password")).toStdString() << endl;

}else cout << "Not Loaded" << endl;

I also tried to load with the line:

Lang.load("de","/esp/Lang","ts");
Lang.load("de","/esp/Lang",".","ts");
Lang.load("de","/esp/Lang","","ts");

my .pro file has the line:

TRANSLATIONS = /esp/Lang/de.ts

and my ts file was done with the linguist tool and is a copy of the skype ts file (see attachment)

thanks!