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. How to prevent standard translations?

How to prevent standard translations?

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 3 Posters 2.9k Views
  • 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.
  • E Offline
    E Offline
    Eeli K
    wrote on last edited by A Former User
    #1

    I have always been annoyed by translated texts, for example message box buttons, in applications which otherwise are not translated. Is there a simple way to prevent Qt library translations in cases where there's no corresponding translation for the application? It's of course possible to reset the texts for the standard buttons etc. but it's clumsy and requires extra coding. (My specific problem at the moment is with Quick Controls 2 Dialog but the same goes for other pre-translated Qt texts.)

    J.HilkJ 1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      You probably need to set the default locale http://doc.qt.io/qt-5/qlocale.html#setDefault

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      E 2 Replies Last reply
      1
      • E Eeli K

        I have always been annoyed by translated texts, for example message box buttons, in applications which otherwise are not translated. Is there a simple way to prevent Qt library translations in cases where there's no corresponding translation for the application? It's of course possible to reset the texts for the standard buttons etc. but it's clumsy and requires extra coding. (My specific problem at the moment is with Quick Controls 2 Dialog but the same goes for other pre-translated Qt texts.)

        J.HilkJ Offline
        J.HilkJ Offline
        J.Hilk
        Moderators
        wrote on last edited by
        #3

        @Eeli-K

        There are translations for such things as message box buttons. They are just not part of your customTranslation.ts/qm file.

        Qt has a couple of finished or nearly finished translations to the most common languages, usually you can find them in this installation path

        ...\Qt\Tools\QtCreator\share\qtcreator\translations
        

        Just install a 2nd QTranslator and everything should be fine, as long as the target language exists.

        //for example:
        uTranslator->   load("mytr_de", trPath);
        qtTranslator->  load("qt_de", qtPath);
        
        qApp->installTranslator(uTranslator);
        qApp->installTranslator(qtTranslator);
        

        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


        Q: What's that?
        A: It's blue light.
        Q: What does it do?
        A: It turns blue.

        1 Reply Last reply
        0
        • VRoninV VRonin

          You probably need to set the default locale http://doc.qt.io/qt-5/qlocale.html#setDefault

          E Offline
          E Offline
          Eeli K
          wrote on last edited by
          #4

          @VRonin Thanks, I have to try it.
          @J-Hilk Sorry, but I explicitly and clearly said I want to PREVENT automatic translations, not to get them working. I tried to google this but everyone was worried about getting their language working so I can understand your answer...

          1 Reply Last reply
          0
          • VRoninV VRonin

            You probably need to set the default locale http://doc.qt.io/qt-5/qlocale.html#setDefault

            E Offline
            E Offline
            Eeli K
            wrote on last edited by
            #5

            @VRonin I tried, but it doesn't work well. This code:

            QLocale loc = QLocale::system();
                qDebug() << loc.country() << loc.language() << loc.decimalPoint() << loc.script() << loc.uiLanguages();
                QLocale loc2(QLocale::English, loc.country());
                QLocale::setDefault(loc2);
                loc = QLocale();
                qDebug() << loc.country() << loc.language() << loc.decimalPoint() << loc.script() << loc.uiLanguages();
            

            leads to this ouput:

            QLocale::Country(UnitedStates) QLocale::Language(English) ',' QLocale::Script(LatinScript) ("en-US")
            QLocale::Country(UnitedStates) QLocale::Language(English) '.' QLocale::Script(LatinScript) ("en", "en-US", "en-Latn-US")
            

            Notice how it changes decimal point, which I don't want. It's weird because my real environment locale is:

            LANG=fi_FI.UTF-8
            LANGUAGE=en_US
            LC_CTYPE="fi_FI.UTF-8"
            LC_NUMERIC=fi_FI.UTF-8
            LC_TIME=fi_FI.UTF-8
            LC_COLLATE=fi_FI.UTF-8
            LC_MONETARY=fi_FI.UTF-8
            LC_MESSAGES="fi_FI.UTF-8"
            LC_PAPER=fi_FI.UTF-8
            LC_NAME=fi_FI.UTF-8
            LC_ADDRESS=fi_FI.UTF-8
            LC_TELEPHONE=fi_FI.UTF-8
            LC_MEASUREMENT=fi_FI.UTF-8
            LC_IDENTIFICATION=fi_FI.UTF-8
            

            (in a linux terminal and in the Qt Creator Project-Run->Run Environment.)

            Why doesn't QLocale work as expected? I want to change the language but keep everything else, just like in my environment. And if someone wants to wonder, the original problem came in a Windows machine, not in this Linux. I'm just coding with Linux right now.

            1 Reply Last reply
            0
            • E Offline
              E Offline
              Eeli K
              wrote on last edited by
              #6

              I surfed through the relevant Qt code. qquickdialogbuttonbox.cpp has this code:

              button->setText(QPlatformTheme::removeMnemonics(QGuiApplicationPrivate::platformTheme()->standardButtonText(standardButton)));
              

              and qplatformtheme.cpp has this:

              QString QPlatformTheme::standardButtonText(int button) const
              {
                  return QPlatformTheme::defaultStandardButtonText(button);
              }
              QString QPlatformTheme::defaultStandardButtonText(int button)
              {
                  switch (button) {
                  case QPlatformDialogHelper::Ok:
                      return QCoreApplication::translate("QPlatformTheme", "OK");
              

              In qcoreapplication.cpp QCoreApplication::translate has:

              for (it = self->d_func()->translators.constBegin(); it != self->d_func()->translators.constEnd(); ++it) {
                          translationFile = *it;
                          result = translationFile->translate(context, sourceText, disambiguation, n);
                          if (!result.isNull())
                              break;
                      }
              

              and as the code and documentation says, the installed QTranslators are prepended, so the latest installed should be found first. If it can translate it with its translate() method the string is returned and no more translators are tried.

              I wrote a translator:

              class NoTranslator: public QTranslator
              {
                  Q_OBJECT
              public:
                  explicit NoTranslator(): QTranslator() {}
                  bool isEmpty() const override {return false;}
                  QString translate(const char *context, const char *sourceText, const char *disambiguation = Q_NULLPTR, int n = -1) const override
                  {
                      qDebug() << sourceText;
                      qDebug() << context;
                      //from qcoreapplication.cpp
                      Q_UNUSED(context)
                      Q_UNUSED(disambiguation)
                      QString ret = QString::fromUtf8(sourceText);
                      if (n >= 0)
                          ret.replace(QLatin1String("%n"), QString::number(n));
                      qDebug() << ret;
                      return ret;
                  }
              };
              

              and installed it in main.cpp:

              QApplication* app{new QApplication(argc, argv)};
                  QTranslator* notr = new NoTranslator();
                  app->installTranslator(notr);
              

              Otherwise it seems to work fine, qDebug() shows it works with qml files. However, I have in a Components2 Dialog a DialogButtonBox with some standard buttons. They are not translated with my translator, instead they obey the LANGUAGE environment variable. Why?

              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