Nominate our 2022 Qt Champions!

How to prevent standard translations?

  • 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.)

  • You probably need to set the default locale

  • Moderators


    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


    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);

  • @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...

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

    QLocale loc = QLocale::system();
        qDebug() << << loc.language() << loc.decimalPoint() << loc.script() << loc.uiLanguages();
        QLocale loc2(QLocale::English,;
        loc = QLocale();
        qDebug() << << 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:


    (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.

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


    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())

    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
        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
            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();

    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?

Log in to reply