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. Help debugging translation failure
Forum Updated to NodeBB v4.3 + New Features

Help debugging translation failure

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 4 Posters 700 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.
  • G Offline
    G Offline
    ghutchis
    wrote on 12 Sept 2021, 19:46 last edited by
    #1

    I've been trying to figure out why translations don't seem to work in my app (and similar code worked in Qt4).

      QLocale currentLocale;
      qDebug() << "Locale: " << currentLocale.name();
    

    This looks good - we see the right LANG show up.

    avoTranslator->load(currentLocale, "avogadroapp", "-", translationPath) returns true - so it finds the QM files
    app.installTranslator() returns true so the translator is loaded

    Nothing in the interface shows up with translation. So I tried:

    qDebug() << "Translated: " << app.translate("MainWindow", "&Export");

    Nope, no translation.

    Again, I just ported our working Qt4 code for Qt 5.12.x.

    Now we use .po files and use lconvert and lrelease to generate the *.qm files:
    lconvert -locations none $x -o ${x%%.po}.ts
    lrelease -compress -removeidentical *.ts

    Again, this was the procedure with our working Qt4 app.

    I'm not sure where to start. Is there a good breakpoint or method to see why my loaded translations aren't working?

    Any ideas on how to debug this would be welcome. (I'm not looking for solutions - just ideas / starting places.)

    Thanks in advance!

    1 Reply Last reply
    0
    • S Offline
      S Offline
      sierdzio
      Moderators
      wrote on 13 Sept 2021, 05:31 last edited by
      #2

      I don't know solution, and I've never worked with .po files, but maybe some of this will help:

      • try out different Qt versions. I've recently had a case where translations generated by Qt 5.12.10 were not working, but when Qt 5.12.5 was used all was fine (with absolutely no code changes!)
      • make sure you clean up whole build directory to always have a clean compilation. It's easy to get stuck with old .qm file when tweaking code and doing incremental builds
      • open the .ts files in Qt Linguist and see if translations are there

      (Z(:^

      G 1 Reply Last reply 13 Sept 2021, 13:50
      1
      • S sierdzio
        13 Sept 2021, 05:31

        I don't know solution, and I've never worked with .po files, but maybe some of this will help:

        • try out different Qt versions. I've recently had a case where translations generated by Qt 5.12.10 were not working, but when Qt 5.12.5 was used all was fine (with absolutely no code changes!)
        • make sure you clean up whole build directory to always have a clean compilation. It's easy to get stuck with old .qm file when tweaking code and doing incremental builds
        • open the .ts files in Qt Linguist and see if translations are there
        G Offline
        G Offline
        ghutchis
        wrote on 13 Sept 2021, 13:50 last edited by
        #3

        @sierdzio - thanks. The files are definitely cleaned up. I'll try a different Qt version soon.

        As to Linguist - the translations are there and "finished" (green check) so that's good.

        Do the .qm files depend on the Qt version that generate them? Like if I generate them on Ubuntu GitHub actions, can I use them on a Mac or Windows system?

        S 1 Reply Last reply 14 Sept 2021, 05:36
        0
        • C Offline
          C Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on 13 Sept 2021, 15:47 last edited by
          #4

          @ghutchis said in Help debugging translation failure:

          "MainWindow", "&Export"

          Please take a look into the ts files and see if there is really a section MainWindow with the to be translated text &Export

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

          G 1 Reply Last reply 13 Sept 2021, 16:16
          1
          • C Christian Ehrlicher
            13 Sept 2021, 15:47

            @ghutchis said in Help debugging translation failure:

            "MainWindow", "&Export"

            Please take a look into the ts files and see if there is really a section MainWindow with the to be translated text &Export

            G Offline
            G Offline
            ghutchis
            wrote on 13 Sept 2021, 16:16 last edited by
            #5

            @Christian-Ehrlicher I've tried everything, including nullptr, and "" (empty string). (The source code for QTranslate converts nullptr into "".)

            The lconvert creates .ts files with no context. So I tried manual translation both with and without context.

            I guess one question is if the tr() calls all have context, do they "fall back" to a translation without context? I'm having trouble following that part of the code:
            https://code.qt.io/cgit/qt/qtbase.git/tree/src/corelib/kernel/qtranslator.cpp

            1 Reply Last reply
            0
            • C Offline
              C Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on 13 Sept 2021, 16:31 last edited by
              #6

              @ghutchis said in Help debugging translation failure:

              do they "fall back" to a translation without context?

              No

              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
                SGaist
                Lifetime Qt Champion
                wrote on 13 Sept 2021, 18:47 last edited by
                #7

                Hi,

                Just a wild idea but did you check for difference in sizes between your old and working files and the new ones ?

                I would also compare with files generated using the classic workflow.

                Using a minimal dummy application might also help find the culprit.

                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
                1
                • G ghutchis
                  13 Sept 2021, 13:50

                  @sierdzio - thanks. The files are definitely cleaned up. I'll try a different Qt version soon.

                  As to Linguist - the translations are there and "finished" (green check) so that's good.

                  Do the .qm files depend on the Qt version that generate them? Like if I generate them on Ubuntu GitHub actions, can I use them on a Mac or Windows system?

                  S Offline
                  S Offline
                  sierdzio
                  Moderators
                  wrote on 14 Sept 2021, 05:36 last edited by
                  #8

                  @ghutchis said in Help debugging translation failure:

                  Do the .qm files depend on the Qt version that generate them? Like if I generate them on Ubuntu GitHub actions, can I use them on a Mac or Windows system?

                  No, the are usually compatible with a very wide range of Qt versions. But as I mentioned in my comment - bugs happen :-)

                  (Z(:^

                  1 Reply Last reply
                  1

                  1/8

                  12 Sept 2021, 19:46

                  • Login

                  • Login or register to search.
                  1 out of 8
                  • First post
                    1/8
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved