Results 1 to 6 of 6

Thread: Internationalization with Qt

  1. #1
    Join Date
    Sep 2006
    Posts
    339
    Thanks
    15
    Thanked 21 Times in 16 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Question Internationalization with Qt

    Hi guys,
    I'm working with a sample program, where I need to make my application translated to other language other than English. I went through Qt linguist manual and followed the steps for translation.

    Can you guys tell me why m not able to convert the english text to french
    Here is my sample program
    Qt Code:
    1. --------------------------------------------------------------------------------------------------
    2. //myfile.h
    3.  
    4. class ArrowPad : public QWidget
    5. {
    6. Q_OBJECT
    7. public:
    8. ArrowPad(QWidget *parent=0, const char *name="ArrowPad" );
    9. ~ArrowPad(){}
    10. private:
    11. QPushButton* left;
    12. QPushButton* right;
    13. QPushButton* down;
    14. };
    15.  
    16. class MainWindow : public QMainWindow
    17. {
    18. Q_OBJECT
    19. public:
    20. MainWindow(QWidget *parent=0, const char *name="MainWindow" );
    21. ~MainWindow(){}
    22.  
    23. private:
    24. QPopupMenu * file;
    25. };
    26.  
    27. ------------------------------------------------------------------------------------------------------
    28. //myfile.cpp
    29.  
    30. ArrowPad::ArrowPad(QWidget *parent, const char *name)
    31. : QWidget(parent, name)
    32. {
    33. up = new QPushButton(tr("&UP"), this) ;
    34. up->setGeometry(200, 100, 40, 40);
    35.  
    36. left = new QPushButton(tr("&LEFT"), this) ;
    37. left->setGeometry(150, 140, 40, 40);
    38.  
    39. right = new QPushButton(tr("&RIGHT"), this) ;
    40. right->setGeometry(250, 140, 40, 40);
    41.  
    42. down = new QPushButton(tr("&DOWN"), this) ;
    43. down->setGeometry(200, 180, 40, 40);
    44.  
    45. }
    46.  
    47. MainWindow::MainWindow(QWidget *parent, const char *name)
    48. :QMainWindow(parent, name)
    49. {
    50. file = new QPopupMenu(this);
    51. menuBar()->insertItem( tr("&File"), file);
    52. file->insertItem( tr("E&xit"), qApp, SLOT(quit()),
    53. tr("Ctrl+Q", "Quit") );
    54. ArrowPad *ap = new ArrowPad( this, "arrow pad" );
    55. setCentralWidget(ap);
    56. resize(500, 500);
    57. }
    58. ------------------------------------------------------------------------------------------------------
    59. //main.cpp
    60.  
    61. #include <qapplication.h>
    62. #include <qpushbutton.h>
    63. #include <qtranslator.h>
    64. #include <qtextcodec.h>
    65. #include "test.h"
    66.  
    67.  
    68. int main( int argc, char **argv )
    69. {
    70. QApplication app( argc, argv );
    71.  
    72. MainWindow mw;
    73.  
    74. QTranslator translator( 0 );
    75. translator.load( "tt2_fr", "." );
    76. app.installTranslator( &translator );
    77.  
    78. app.setMainWidget( &mw );
    79. mw.show();
    80. return app.exec();
    81. }
    To copy to clipboard, switch view to plain text mode 

    I have also created *.ts and *.qm files using lupdate and lrelease but still the program shows me english text. I have taken this sample from Qt linguist manual, section->Programmers

    Any comment will be highly appreciated
    Thanx

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Internationalization with Qt

    What does QTranslator::load() return?
    J-P Nurmi

  3. #3
    Join Date
    Sep 2006
    Posts
    339
    Thanks
    15
    Thanked 21 Times in 16 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Internationalization with Qt

    Quote Originally Posted by jpn View Post
    What does QTranslator::load() return?
    Hi thankx for your reply,
    I have just added this code in my main.cpp

    Qt Code:
    1. bool flag = translator.load( "tt2_fr", "." );
    2. if(flag)
    3. qDebug("File loaded successfully");
    4. else
    5. qDebug("Failed");
    To copy to clipboard, switch view to plain text mode 

    This returns true and displays File loaded successfully.

    Thankx

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Internationalization with Qt

    Load the translator before creating the window or provide support for language change event for the window.

  5. #5
    Join Date
    Sep 2006
    Posts
    339
    Thanks
    15
    Thanked 21 Times in 16 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Internationalization with Qt

    Quote Originally Posted by wysota View Post
    Load the translator before creating the window or provide support for language change event for the window.
    Hi, Can you please explain with an example as I'm unable to get you.

  6. #6
    Join Date
    Sep 2006
    Posts
    339
    Thanks
    15
    Thanked 21 Times in 16 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Internationalization with Qt

    Quote Originally Posted by vermarajeev View Post
    Hi, Can you please explain with an example as I'm unable to get you.
    hey Thankx it works,
    I loaded the translator before creating the window

    Thankx a lot,

Similar Threads

  1. Problem in Internationalization with Qt
    By zlatko in forum Qt Programming
    Replies: 1
    Last Post: 21st March 2006, 15:06
  2. Plugin and internationalization
    By blackliteon in forum Qt Programming
    Replies: 10
    Last Post: 14th February 2006, 07:29

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.