Important: Please read the Qt Code of Conduct -

several texts don't get translated texts

  • Hi,

    this is just for feedback ...

    I wondered, why some texts get translated, and others don't.
    I checked language file with linguist, where i.e. a qtcreator form is displayed translated, but my app does not receive translated texts.

    So I did some additional tests.

    My startup is stil the same (for creation issue of QLocale):

    int main(int argc, char *argv[]) {
      try {
          QTranslator       translator;
          QApplication      a(argc, argv);
          QLocale           sysLocale;
          QLocale::Language lang    = sysLocale.language();
          QLocale::Country  country =;
          QLocale           curLocale(lang, country);
          bool              ok = translator.load(curLocale
                                              , "FalconView"
                                              , "_"
                                              , "../FalconView/src/i18n");
          qDebug() << "locale messages found: " << ok;

    I get the message, that translator found the message file, therefore I thought, that all texts should get translated variants ...

    One of my recent forms use qtcreator form as member var
    Ui::JogForm* ui; which gets initialized by constructor:

    JogView::JogView(QWidget* parent)
     : DynCenterWidget(QString(), JogView::className, false, parent)
     , ui(new Ui::JogForm()) {
    //  ...

    setupUI created by moc-compiler already calls retranslateUi, so I thought translated texts should be available.

    For testing purpose I copied code from retranslateUi into my widget code, where I changed the translating calls like this:

      ui->jVn->setText(QCoreApplication::translate("JogForm", "V-", nullptr));
      ui->cbRapid->setText(tr("Rapid", "JogForm"));
      ui->cbSingleStep->setText(Core().translator()->translate("JogForm", "single Step"));

    The first line is what moc-compiler generates - this variant does not get translated text.

    Second line is what I usually write in my widget codes (usually without context info) - this variant did not get translated text (I tried with and without context info).

    For the third line I copied the pointer of translator (created in main) into my kernel (some kind of singleton). The call is not optimized for usage yet, just a test - but that variant did provide the localized text.

  • Lifetime Qt Champion

    Please provide a minimal, compilable example to reproduce the issue. A simple main() should be enough here to reproduce the issue.

  • Hi Chris,

    thank you for your attention.

    With the locale-issue it was easy, that always failed. Now its different and the point is, I have no idea, where it depends on, if texts get translated or not. About 20-30% of my texts where translated and the rest was not.

    So I don't know, how to reduce amount of code.

    Small projects always work.

    Just to avoid misunderstandings: the three samples use different texts, but I tested it with the same text. So no translation issue - for sure.

    I can't guess, whether it is related on locale or handling of translator instances ...

    Therefore feedback only.

  • Lifetime Qt Champion

    Then reduce your big code until it works or you have a minimal reproducible example.

  • Actually I'm working on fixing my code.

    For elements from qtcreator forms the fix is some kind of ridiculous. Here for a pushbutton (GCodeEditorForm is the name of the top-widget in qtcreator):

    pbOpen->setText(Core().tr(pbOpen->text().toStdString().c_str(), "GCodeEditorForm"));

  • Lifetime Qt Champion

    There is no need to fix something which is created by the uic. End especially not in this very ridiculously way.

  • I never had a problem with texts not being translated. You should first make sure that there is actually a translation for everything. May try to regenerate the list of texts to be translated and then have a look with Linguist. Also, you could try to figure out if the correct entry in the translation file appears. If there is no translation available in the translation file (wrong context or whatever) you cannot expect the translated text to show up.

    Missing translations is usually not because of broken code.

  • Hi Simon,

    look, if such dump workaround works - taking text out of a label, translate it and put it back into the label - then its not an issue with the translated texts.
    I suppose, its a timing issue, but its hard to get rid of.
    I have static forms and dynamically loaded forms.
    If i.e. the translator would have been to late created, then all dynamic loaded forms should have been translated, but that's not the case.

    Any way - thanks for your attention!

  • Lifetime Qt Champion


    Did you try moving your translator object after the QApplication as is recommended ?

Log in to reply