Results 1 to 8 of 8

Thread: Problem with internationalisation

  1. #1
    piotrpsz Guest

    Default Problem with internationalisation

    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:hrase = 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

  2. #2
    piotrpsz Guest

    Unhappy Problem with internationalisation (Next check)

    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

  3. #3
    Join Date
    Jan 2006
    Location
    Scandinavia
    Posts
    62
    Thanks
    5
    Thanked 2 Times in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem with internationalisation

    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
    Qt Code:
    1. // main.cc
    2. /* TRANSLATOR tecams::main::QObject */
    3. // to get the [B]context[/B] right in the main.cc file which does not have the Q_OBJECT macro
    4. QTranslator app_translator( 0 );
    5. const bool ret = app_translator.load( "bsc_pl.qm", qApp->applicationDirPath() );
    6. app.installTranslator( &app_translator );
    7.  
    8. qDebug( QObject::tr("Testing that I can translate this sentence", "some comment"));
    To copy to clipboard, switch view to plain text mode 

    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.

  4. #4
    piotrpsz Guest

    Default Re: Problem with internationalisation

    Hi Kjell

    Quote Originally Posted by KjellKod
    I.e. something like
    Qt Code:
    1. qDebug( QObject::tr("Testing that I can translate this sentence", "some comment"));
    To copy to clipboard, switch view to plain text mode 
    Good idea.
    You are around.
    I try this (in main function):
    Qt Code:
    1. qDebug( QObject::tr( "english text" ));
    To copy to clipboard, switch view to plain text mode 

    Next I lupdate, translate and so forth.
    And qDebug displays correcte Polish text:
    Qt Code:
    1. tekst po polsku
    To copy to clipboard, switch view to plain text mode 

    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'.

  5. #5
    Join Date
    Jan 2006
    Location
    Scandinavia
    Posts
    62
    Thanks
    5
    Thanked 2 Times in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem with internationalisation

    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.

  6. #6
    piotrpsz Guest

    Default Bingo !!!!!!!!

    I found the problem

    Was:

    Qt Code:
    1. const QString Attr::FILE_NAME_LABEL = tr( "File name: " );
    2. .....
    3.  
    4. Attr::Attr( QWidget* const in_parent, const QString& in_dir, const ViewTable::SelectedItems& in_items )
    5. : QDialog( in_parent )
    6. .....
    7. , d_fname_label ( new QLabel( FILE_NAME_LABEL , this ) )
    8. {
    9. }
    To copy to clipboard, switch view to plain text mode 

    And now:
    Qt Code:
    1. , d_fname_label ( new QLabel( tr( FILE_NAME_LABEL ), this ) )
    To copy to clipboard, switch view to plain text mode 

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

    Best Regards
    Piotr

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Bingo !!!!!!!!

    Quote Originally Posted by piotrpsz
    d_fname_label ( new QLabel( tr( FILE_NAME_LABEL ), this ) )
    In such case you have to use:
    Qt Code:
    1. const QString Attr::FILE_NAME_LABEL = QT_TR_NOOP( "File name: " );
    To copy to clipboard, switch view to plain text mode 
    to mark that your string should be included in .ts file.

  8. #8
    piotrpsz Guest

    Default Re: Bingo !!!!!!!!

    Quote Originally Posted by jacek
    In such case you have to use:
    Qt Code:
    1. const QString Attr::FILE_NAME_LABEL = QT_TR_NOOP( "File name: " );
    To copy to clipboard, switch view to plain text mode 
    to mark that your string should be included in .ts file.


    Of course
    I made already.
    Thank you.

Similar Threads

  1. deployment problem: msvc++ 2008 Express, Qt 4.4.3
    By vonCZ in forum Qt Programming
    Replies: 7
    Last Post: 10th November 2008, 14:38
  2. Weird problem: multithread QT app kills my linux
    By Ishark in forum Qt Programming
    Replies: 2
    Last Post: 8th August 2008, 09:12
  3. Steps in solving a programming problem?
    By triperzonak in forum General Programming
    Replies: 8
    Last Post: 5th August 2008, 08:47
  4. problem with paint and erase in frame
    By M.A.M in forum Qt Programming
    Replies: 9
    Last Post: 4th May 2008, 20:17
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.