Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Unable to use new QTranslator::load() (Qt 4.8)



  • Hello,

    With Qt 4.8.0, there's a new overload for QTranslator::load():
    http://doc.qt.nokia.com/main-snapshot/qtranslator.html#load-2

    It is documented as follows:
    @bool QTranslator::load ( const QLocale & locale, const QString & filename, const QString & prefix = QString(), const QString & directory = QString(), const QString & suffix = QString() )@
    With a short example:

    bq. For example, an application running in the locale with the following ui languages - "es", "fr-CA", "de" might call load(QLocale::system(), "foo", ".", "/opt/foolib", ".qm"). load() would replace '-' (dash) with '_' (underscore) in the ui language and then try to open the first existing readable file from this list: [...]

    So I tried with the following lines:
    @
    ...
    QApplication app(argc, argv);

    QTranslator theTranslator;
    theTranslator.load(QLocale::system(), "theTranslationFile", "_", "/the/path/to/the/translation/files");
    app.installTranslator(&theTranslator);

    QDebug() << QLocale::system().name();
    ...

    @
    and set 2 different translation files: one for french and one for canadian french (through ts files):
    @theTranslationFile_fr.qm
    theTranslationFile_fr_CA.qm
    @

    Then I set the shell variable to LANG=fr_CA and run the application.

    The QDebug() command outputs "fr_CA" while the text displayed on the widgets comes from the ...fr.qm file, not from fr_CA.qm files :-(

    When loading the translator via the following, it works:
    @
    theTranslator.load("theTranslationFile_"+QLocale::system().name(),"/the/path/to/the/translation/files");
    @

    Is something above bad?

    I'm using MacOS X 10.7

    Cheers



  • Hi,

    Can you paste the result of QLocale::uiLanguages () ?

    Thanks



  • Hi 1+1=2 ;-)

    LANG=fr_BE: @
    QLocale::system().uiLanguages() : ("en", "ja", "fr", "de", "es", "it", "pt", "pt_PT", "nl", "sv", "nb", "da", "fi", "ru", "pl", "zh-Hans", "zh-Hant", "ko", "ar", "cs", "hu", "tr")
    QLocale::system().name() : "fr_BE"
    @

    LANG=fr_FR: @
    QLocale::system().uiLanguages() = ("en", "ja", "fr", "de", "es", "it", "pt", "pt_PT", "nl", "sv", "nb", "da", "fi", "ru", "pl", "zh-Hans", "zh-Hant", "ko", "ar", "cs", "hu", "tr")
    QLocale::system().name() = "fr_FR"
    @

    LANG=fr_CA: @
    QLocale::system().uiLanguages() = ("en", "ja", "fr", "de", "es", "it", "pt", "pt_PT", "nl", "sv", "nb", "da", "fi", "ru", "pl", "zh-Hans", "zh-Hant", "ko", "ar", "cs", "hu", "tr")
    QLocale::system().name() = "fr_CA"
    @

    The output of uiLanguages() is related with the Mac OS System Preferences > Language & Text > Language order.



  • It's clear now,

    As
    @
    bool QTranslator::load ( const QLocale & locale, const QString & filename, const QString & prefix = QString(), const QString & directory = QString(), const QString & suffix = QString() )
    @
    will use the list returned by QLocale::uiLanguages (), but fr_CA, does belong to the list.



  • Indeed, I should read the doc with eyes open ;-)

    This raises the following question: how to set manually fr_CA as the first language in this list from the shell? E.g. for testing purpose.


Log in to reply