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. several texts don't get translated texts
Forum Updated to NodeBB v4.3 + New Features

several texts don't get translated texts

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 4 Posters 517 Views 2 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
    django.Reinhard
    wrote on last edited by
    #1

    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 = sysLocale.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(this);
    //  ...
      }
    

    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.

    1 Reply Last reply
    0
    • Christian EhrlicherC Online
      Christian EhrlicherC Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

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

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      0
      • D Offline
        D Offline
        django.Reinhard
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • Christian EhrlicherC Online
          Christian EhrlicherC Online
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

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

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          1 Reply Last reply
          0
          • D Offline
            D Offline
            django.Reinhard
            wrote on last edited by
            #5

            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"));
            
            1 Reply Last reply
            0
            • Christian EhrlicherC Online
              Christian EhrlicherC Online
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #6

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

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              1 Reply Last reply
              0
              • S Offline
                S Offline
                SimonSchroeder
                wrote on last edited by
                #7

                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.

                1 Reply Last reply
                0
                • D Offline
                  D Offline
                  django.Reinhard
                  wrote on last edited by
                  #8

                  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!

                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    Hi,

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

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    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