Results 1 to 6 of 6

Thread: Translation system simply not working!

  1. #1
    Join Date
    Jun 2011
    Location
    Porto Alegre, Brazil
    Posts
    482
    Thanks
    165
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Angry Translation system simply not working!

    Hello!

    I'm knocking my head for some hours now trying to understand why my translation mechanism is not working despite the fact that I followed all translation manuals and examples (no to mention that to translate seems a pretty easy task). What happens is that I created the .ts files, translated (parts of it) in Qt Linguist, created the .qm files and added them to the specified folder. Then I call QTranslator etc. in my program and both finding the translator files as well as loading them returns no error - but no translation actually occurs in the application.

    Here is (most of) the code so you all may check if I missed something:

    Qt Code:
    1. //main.cpp
    2. qint32 main(qint32 argc, char *argv[])
    3. {
    4. QApplication::setGraphicsSystem("raster");
    5.  
    6. //
    7. QApplication app(argc, argv);
    8. app.setApplicationName("RE8000");
    9. app.setApplicationVersion(APP_VERSION);
    10. app.setOrganizationName("XXXX");
    11. app.setOrganizationDomain("http://www.xxxx.com.br/");
    12.  
    13. app.thread()->setPriority(QThread::HighestPriority);
    14.  
    15. if (!setTranslation())
    16. CFG_ED.setProfileLanguage(CFG::Language_English);
    17.  
    18. //Starts creating the widgets
    19. g_mainSplashScreen = new SplashScreen(QPixmap(":/Images/EntraceImage.bmp"), Qt::WindowStaysOnTopHint);
    20. g_mainSplashScreen->setGeometry((QApplication::desktop()->width() - g_mainSplashScreen->pixmap().width())/2,
    21. (QApplication::desktop()->height() - g_mainSplashScreen->height())/2,
    22. g_mainSplashScreen->pixmap().width(),g_mainSplashScreen->height());
    23. }
    24.  
    25. //...
    26. static bool setTranslation()
    27. {
    28. const CFG::AvailableLanguages currLanguage = CFG_ED.profileLanguage();
    29.  
    30. Settings::Profile::ProfileCenterView::setDefaultLocale(currLanguage);
    31.  
    32. if (Q_UNLIKELY(!Settings::Profile::ProfileCenterView::installLanguage(currLanguage)))
    33. {
    34. mLog("An error occured while trying to load the translation file (static bool setTranslation(QApplication&))");
    35.  
    36. return false;
    37. }
    38.  
    39. return true;
    40. }
    41.  
    42. //Other files
    43. void ProfileCenterView::setDefaultLocale(const Config::UserCfgSingletom::AvailableLanguages language) (static)
    44. {
    45. switch (language)
    46. {
    47. case CFG::Language_English: QLocale::setDefault(QLocale(QLocale::English,QLocale::UnitedStates)); break;
    48. case CFG::Language_Espanol: QLocale::setDefault(QLocale(QLocale::Spanish,QLocale::LatinAmericaAndTheCaribbean)); break;
    49. case CFG::Language_PortugueseBR: QLocale::setDefault(QLocale(QLocale::Portuguese,QLocale::Brazil)); break;
    50.  
    51. default: QLocale::setDefault(QLocale::c()); break;
    52. }
    53. }
    54.  
    55. bool ProfileCenterView::installLanguage(const Config::UserCfgSingletom::AvailableLanguages language) (static)
    56. {
    57. if (language == CFG::Language_English)
    58. return true;
    59.  
    60. //
    61. QDir translationDir(DEFAULT_TRANSLATION_PATH);
    62.  
    63. QStringList fileNameList = translationDir.entryList(QStringList("*.qm"),QDir::Files,QDir::Name);
    64.  
    65. if (Q_UNLIKELY(fileNameList.isEmpty()))
    66. {
    67. mDebugS("Error while trying to install translator: no translator files were found (ProfileCenterView::installLanguage))");
    68. mLog("No translation files were found");
    69.  
    70. return false;
    71. }
    72.  
    73. //![] Install selected translation
    74. QTranslator translator;
    75.  
    76. if (Q_UNLIKELY(!translator.load(QLocale(),"re8000","_",DEFAULT_TRANSLATION_PATH,".qm")))
    77. {
    78. mDebugS("Error while trying to install translator: error while loading file (ProfileCenterView::installLanguage)");
    79. mLog("Error when trying to load the translation file");
    80.  
    81. return false;
    82. }
    83.  
    84. qApp->installTranslator(&translator);
    85.  
    86. return true;
    87. }
    To copy to clipboard, switch view to plain text mode 

    Remember: as I sad, no errors are returned; only the translations don't appear as if I hadn't done any translations to the .ts file (which I did!).


    What could be wrong?

    I'm glad for any help,

    Momergil
    May the Lord be with you. Always.

  2. #2
    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: Translation system simply not working!

    Guess what happens to QTranslator instance after the scope where it is declared ends...
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. The following user says thank you to wysota for this useful post:

    Momergil (31st July 2014)

  4. #3
    Join Date
    Jun 2011
    Location
    Porto Alegre, Brazil
    Posts
    482
    Thanks
    165
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Translation system simply not working!

    Quote Originally Posted by wysota View Post
    Guess what happens to QTranslator instance after the scope where it is declared ends...
    Hmm! So you mean that the QTranslator object need to be kept alive during the whole translation process, not only for the QTranslator::load() operation? Well, I'll check that out after dinner and return with the results!
    May the Lord be with you. Always.

  5. #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: Translation system simply not working!

    Think why you are passing a pointer to the object to installTranslator...
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #5
    Join Date
    Jun 2011
    Location
    Porto Alegre, Brazil
    Posts
    482
    Thanks
    165
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Translation system simply not working!

    Quote Originally Posted by wysota View Post
    Think why you are passing a pointer to the object to installTranslator...
    hmm, ok, you certainly made a point

    So now the QTranslator inside my installLanguage method is a static one and everything is working 'fine' The other problem I'm having was mentioned here.


    Thanks,

    Momergil
    May the Lord be with you. Always.

  7. #6
    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: Translation system simply not working!

    QTranslator is a QObject so you can create it on heap passing a parent to it and then forget about the object if you don't have functionality for dynamically unloading translations in your application.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. System native QDialog and its translation
    By SeeLook in forum Qt Programming
    Replies: 0
    Last Post: 28th October 2012, 18:38
  2. QFormBuilder: Translation not working
    By kalli in forum Qt Programming
    Replies: 0
    Last Post: 28th June 2010, 22:54
  3. Translation not working for all the classes
    By chandan in forum Qt Tools
    Replies: 1
    Last Post: 24th May 2010, 13:45
  4. Qt windowing system Working
    By awalesminfo in forum Newbie
    Replies: 1
    Last Post: 30th December 2008, 13:48
  5. QProcess / system call not working under linux. Why?
    By johnny_sparx in forum Qt Programming
    Replies: 12
    Last Post: 11th March 2006, 01:32

Tags for this Thread

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.