PDA

View Full Version : Problem with internationalisation



piotrpsz
5th February 2006, 09:42
Hi,

I have a program in which descriptions are in English.
I would like to use two another langauges (Polish end German).
I trying to use QTranslator. But this don't function.

I have a dialog width static const text, for example:
const QString ClassName::phrase = tr( "english_word' );

I create '.ts' file, I translate this on in Qt Linguist and save like '.mq'.
In function 'main' I wrote followed code:

QTranslator app_translator( 0 );
const bool ret = app_translator.load( "bsc_pl.qm", qApp->applicationDirPath() );
app.installTranslator( &app_translator );

All is OK. ret is true.

Next I checking all transaltions:

QValueList<QTranslatorMessage> list = app_translator.messages();
QValueList<QTranslatorMessage>::Iterator it = list.begin();
while ( it != list.end() ) {
qWarning( (*it).translation() );
++it;
}

Is OK. I see all my translations.

But. Dialog is always English.
WHY?

Best Regards
Piotr

piotrpsz
5th February 2006, 10:02
I try to check:

QTranslatorMessage msg = app_translator.findMessage( "Attr", "File name: " );
QString pl = msg.translation();
qWarning( "Polish: " + pl );

And is excellent. Text on console is corrent.
But dialog is English

KjellKod
5th February 2006, 11:26
Hi,

In your example above you find the message -which is good and fine- but is expected since you had translated it and made it into a qm file. As an additional test I would just try to make a super simple Hello World program to just test that the basic case actually works. Just to see that you haven't made any blunders.

I.e. something like


// main.cc
/* TRANSLATOR tecams::main::QObject */
// to get the context right in the main.cc file which does not have the Q_OBJECT macro
QTranslator app_translator( 0 );
const bool ret = app_translator.load( "bsc_pl.qm", qApp->applicationDirPath() );
app.installTranslator( &app_translator );

qDebug( QObject::tr("Testing that I can translate this sentence", "some comment"));


Other reasons why it may not work:
* Context related. i.e. tr() cannot do the lookup correct, but lupdate can generate the ts file.
* You instantiate the dialogue where you have the text before you've installed the translator.

piotrpsz
5th February 2006, 12:10
Hi Kjell :)



I.e. something like


qDebug( QObject::tr("Testing that I can translate this sentence", "some comment"));



Good idea.
You are around.
I try this (in main function):


qDebug( QObject::tr( "english text" ));


Next I lupdate, translate and so forth.
And qDebug displays correcte Polish text:


tekst po polsku


And next I check qDebug in constructor in my dialog.
qDebug displays correcte Polish text !!!!!!!!!!!!!
But dialog displays English.



Other reasons why it may not work:
* Context related. i.e. tr() cannot do the lookup correct, but lupdate can generate the ts file.


Is this possible?



* You instantiate the dialogue where you have the text before you've installed the translator.


Inpossible. I'm installing translator in function 'main'.

KjellKod
5th February 2006, 12:23
Inpossible. I'm installing translator in function 'main'.
OK, and you do initiate the window that causes the dialogue to appear after that you've installed the translator, right? Otherwise you would have problems

Regarding contect related problems:

Is this possible? Yes. it is.

Can you post the code of the dialogue where you have the text?
Also: As another test. try qDebug again. at the same place where you have the dialogue with exactly the same input to the translation to see that everything is OK there as well.

piotrpsz
5th February 2006, 12:24
I found the problem :)

Was:



const QString Attr::FILE_NAME_LABEL = tr( "File name: " );
.....

Attr::Attr( QWidget* const in_parent, const QString& in_dir, const ViewTable::SelectedItems& in_items )
: QDialog( in_parent )
.....
, d_fname_label ( new QLabel( FILE_NAME_LABEL , this ) )
{
}


And now:


, d_fname_label ( new QLabel( tr( FILE_NAME_LABEL ), this ) )


In initialisation in constructor must be 'tr' !!!!!!

Best Regards
Piotr

jacek
5th February 2006, 16:05
d_fname_label ( new QLabel( tr( FILE_NAME_LABEL ), this ) )
In such case you have to use:
const QString Attr::FILE_NAME_LABEL = QT_TR_NOOP( "File name: " );to mark that your string should be included in .ts file.

piotrpsz
5th February 2006, 17:53
In such case you have to use:

const QString Attr::FILE_NAME_LABEL = QT_TR_NOOP( "File name: " );
to mark that your string should be included in .ts file.

:)

Of course :)
I made already.
Thank you.