Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Unable to use new QTranslator::load() (Qt 4.8)
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 4.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    DerekDomino
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dbzhang800
      wrote on last edited by
      #2

      Hi,

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

      Thanks

      1 Reply Last reply
      0
      • D Offline
        D Offline
        DerekDomino
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • D Offline
          D Offline
          dbzhang800
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          • D Offline
            D Offline
            DerekDomino
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved