Results 1 to 3 of 3

Thread: Problems about Dynamic Language Switching

  1. #1
    Join Date
    Apr 2008
    Posts
    44
    Thanks
    21
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Question Problems about Dynamic Language Switching

    hi to all!
    I'd like to do dynamic language switching in my application,but there is a problem.

    there are three language in my project:english, Chinese simplified and Chinese Traditional. I chagne the language by the menu.
    Qt Code:
    1. connect(actE,SIGNAL(triggered()),this,SLOT(LanEnlish()));
    2.  
    3.  
    4. if(languageType == 0)
    5. {
    6. return;
    7. }
    8.  
    9. translator.load("language_Eng");
    10. qApp->installTranslator(&translator);
    11. retranslateUi(this);
    12.  
    13. //call the retranslateUi() in the ComSetup and Navigation, the ComSetup and Navigation are dialogs designered by the QT designer
    14. ComSetup->SwitchLanguage();
    15. Navigation->SwitchLanguage();
    16.  
    17. languageType = 0;
    To copy to clipboard, switch view to plain text mode 

    Now the problem is like this: the language are designed in the QT designer in the dialog could be translated exactly. the language that added to the dialog in the program(.cpp)can't be translated. for example, there is "dockWidget = new QDockWidget(tr("Navigation"),this);" in the .cpp,the "Navigation" can't be translated. i make sure the according word has been translateed in the "language_Eng".


    Do you know what I mean? Have you got any ideas what's wrong with it ?
    Regards to all.

  2. #2
    Join Date
    Apr 2009
    Posts
    17
    Thanks
    7
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problems about Dynamic Language Switching

    I have a similar issue, what i have done, is it will translate all sub widgets (all widgets that are part of the program) but will not translate MainWindow. I use Qt SDK 2010.01 and all my ui is designed in QtCreators Designer.

    here is my code that i use for switching between languages, SoftProjector is my MainWindow:

    softprojector.h
    Qt Code:
    1. private:
    2. QTranslator translator;
    To copy to clipboard, switch view to plain text mode 


    softprojector.cpp
    Qt Code:
    1. void SoftProjector::on_actionRussian_triggered()
    2. {
    3. translator.load(":sotftpro_ru");
    4. QApplication::installTranslator(&translator);
    5. }
    6.  
    7. void SoftProjector::on_actionEnglish_triggered()
    8. {
    9. QApplication::removeTranslator(&translator);
    10. }
    To copy to clipboard, switch view to plain text mode 

    The code will translate everything but the MainWindow.

    What changes do i need to make so that it would dynamically translate entire program (not in main.cpp)?

    Thanks

  3. #3
    Join Date
    Apr 2009
    Posts
    17
    Thanks
    7
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Cool Re: Problems about Dynamic Language Switching

    Quote Originally Posted by to_guliang View Post
    Now the problem is like this: the language are designed in the QT designer in the dialog could be translated exactly. the language that added to the dialog in the program(.cpp)can't be translated. for example, there is "dockWidget = new QDockWidget(tr("Navigation"),this);" in the .cpp,the "Navigation" can't be translated. i make sure the according word has been translateed in the "language_Eng".


    Do you know what I mean? Have you got any ideas what's wrong with it ?
    Regards to all.
    Untitled.jpg

    In Designer make sure that translatable property of all text items have been check. see attachment image
    I believe this is the same as using tr() in code.

Similar Threads

  1. Replies: 17
    Last Post: 26th January 2010, 20:21
  2. QCalendarWidget and dynamic language switching
    By tora in forum Qt Programming
    Replies: 4
    Last Post: 23rd September 2009, 12:06
  3. Switching 5.2 from 5.0.2
    By baray98 in forum Qwt
    Replies: 1
    Last Post: 11th May 2009, 17:59
  4. Dynamic Language Switching
    By Salazaar in forum Newbie
    Replies: 7
    Last Post: 29th June 2007, 12:00
  5. Switching static to dynamic ui loading
    By s_a_white in forum Newbie
    Replies: 4
    Last Post: 26th June 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
  •  
Qt is a trademark of The Qt Company.