Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-54373

QTranslator select wrong translations

    XMLWordPrintable

Details

    • Bug
    • Resolution: Incomplete
    • Not Evaluated
    • None
    • 5.6.0, 5.6.1, 5.7.0
    • Core: Locales (i18n)
    • None
    • OSX El Capitan

    Description

      QTranslator is behaving wrongly on my system.

      My system regional settings are configured like this:

      • Preferred languages: English, French, German
      • Region: France - French
      • Formatting language: French

      Qt is correctly discovering my locale

      QLocale(French, Latin, France) ("en", "fr", "de", "zh-Hans", "zh-Hant", "ja", "es", "it", "nl", "ko", "pt-BR", "pt-PT", "da", "fi", "nb", "sv", "ru", "pl", "tr", "ar", "th", "cs", "hu", "ca", "hr", "el", "he", "ro", "sk", "uk", "id", "ms", "vi")

      Though QTranslator taking a QLocale ctor parameter fallback loading is not working fine.
      Qt is natively english and do not propose 'en' qm files.
      Because of that every Qt application open in French (or any of the matching preferred language appearing in QLocale::uiLanguages()).
      English in this case is a never reachable language for my configuration.

      Probably QCoreApplication is missing a property which could help the fallback mechanism, something like: QCoreApplication::nativeLanguage() which the application author must set (defaulting to the system local language to keep compatibility).
      This property will describe the language used in the source code tr() stuff, and the fallback mechanism could know that English is available and not load French or next preferred language translations.

      Test case:

      #include <QCoreApplication>
      #include <QTranslator>
      #include <QLibraryInfo>
      #include <QDir>
      #include <QDebug>
      
      void load(const QLocale &locale, const QString &name, const QString& path) {
          auto translator = new QTranslator(qApp);
      
          if (translator->load(locale, name, "_", path)) {
              qApp->installTranslator(translator);
              qWarning("%s ok", qPrintable(name));
          }
          else {
              delete translator;
              qWarning("%s fails", qPrintable(name));
          }
      }
      
      int main(int argc, char *argv[])
      {
          QCoreApplication a(argc, argv);
          //a.setProperty("nativeLanguage", "en");
      
          const QString qmPath = QLibraryInfo::location(QLibraryInfo::TranslationsPath);
          const QLocale locale;
      
          qWarning() << locale << locale.uiLanguages();
          qWarning() << qmPath;
      
          load(locale, "qtbase", qmPath);
          load(locale, "qt_help", qmPath);
          load(locale, "gammaray", "/Volumes/Shared/Development/Builds/QtAuto/GammaRay-Desktop_Qt_5_6_1_clang_64bit-Release/translations");
      
          qWarning() << "QAbstractSocket::Connection refused: " << QCoreApplication::translate("QAbstractSocket", "Connection refused");
          qWarning() << "QHelpSearchQueryWidget::Search: " << QCoreApplication::translate("QHelpSearchQueryWidget", "Search");
          qWarning() << "GammaRay::AboutPluginsDialog::Failed Plugins: " << QCoreApplication::translate("GammaRay::AboutPluginsDialog", "Failed Plugins");
          //qWarning() << "qm:" << QDir(qmPath).entryList({ "qtbase*.qm", "qt_help*.qm" });
      
          return 0;
      }
      

      Attachments

        Issue Links

          For Gerrit Dashboard: QTBUG-54373
          # Subject Branch Project Status CR V

          Activity

            People

              thiago Thiago Macieira
              filipe.azevedo Filipe Azevedo
              Votes:
              4 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes