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. Translation does not work with Qt 6.7
Forum Updated to NodeBB v4.3 + New Features

Translation does not work with Qt 6.7

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 2 Posters 695 Views 1 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.
  • K Offline
    K Offline
    KejPi
    wrote on last edited by KejPi
    #1

    Hello All,

    I found a problem with application translations that do not work since Qt 6.7 (it works fine with Qt 6.6.3). It seems that the problem is with loading of the translation files because *.qm files are generated as before.

    CMakeLists.txt

    set(TSFILES
        l10n/${TARGET}_cs.ts
        l10n/${TARGET}_de.ts
        l10n/${TARGET}_pl.ts
    )
    
    qt_add_translations(${TARGET} TS_FILES ${TSFILES}
        LUPDATE_OPTIONS "-noobsolete"
    )
    

    main.cpp

        QLocale::Language lang = QLocale::codeToLanguage(settings->value("language", QString("")).toString());
    
       QTranslator translator;
            if (QLocale::AnyLanguage == lang)
            {   // system default
                if (translator.load(QLocale(), QLatin1String("AbracaDABra"), QLatin1String("_"), QLatin1String(":/i18n")))
                {
                    a.installTranslator(&translator);
                }
            }
            else if (QLocale::English != lang)
            {   // user selected translation
                if (translator.load(QString("AbracaDABra_%1").arg(QLocale::languageToCode(lang)), QLatin1String(":/i18n")))
                {
                    a.installTranslator(&translator);
                }
            }
    

    translator.load() returns false in both cases and no translation is loaded.
    I found there are some changes in qt_add_translations but I think I call it in compatible way.

    Any idea? Thanks!

    1 Reply Last reply
    0
    • K Offline
      K Offline
      KejPi
      wrote on last edited by KejPi
      #7

      They should be added according to documentation

      Qt 6.5.3

      ":/i18n"
      ":/i18n/AbracaDABra_pl.qm"
      ":/i18n/AbracaDABra_cs.qm"
      ":/i18n/AbracaDABra_de.qm"
      

      Qt 6.7.0

      ":/i18n"
      ":/i18n/gui"
      ":/i18n/gui/AbracaDABra_pl.qm"
      ":/i18n/gui/AbracaDABra_cs.qm"
      ":/i18n/gui/AbracaDABra_de.qm"
      

      So it is added in both cases but 6.7 adds subdirectory according to project structure (translation files are handled from CMakeLists.txt located in gui directory). It is probably correct behavior but it makes the code incompatible. I will solve it by compiler switch and make this topic as solved.

      Thank you for your help!

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

        How to you add the files to your resource? Make sure they are at the location you're expecting them. Use e.g. QFile::exists().

        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
        • K Offline
          K Offline
          KejPi
          wrote on last edited by KejPi
          #3

          I do not actually add them in resources explicitly but it was always working so far. The complete source code of my app is on GitHub: https://github.com/KejPi/AbracaDABra

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

            Please check with QFile::exists() ...

            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
            1
            • K Offline
              K Offline
              KejPi
              wrote on last edited by KejPi
              #5

              Yes, that's it.

              Application compiled with:
              Qt6.5.3: File exists? ":/i18n/AbracaDABra_de.qm" true
              Qt6.7.0: File exists? ":/i18n/AbracaDABra_de.qm" false

              So it means that with Qt 6.7 it is not added to resources automatically. So the question is how to add it to resources automatically as it is done with Qt < 6.7?
              Note: I can see the file is generated in both cases.

              Christian EhrlicherC 1 Reply Last reply
              1
              • K KejPi

                Yes, that's it.

                Application compiled with:
                Qt6.5.3: File exists? ":/i18n/AbracaDABra_de.qm" true
                Qt6.7.0: File exists? ":/i18n/AbracaDABra_de.qm" false

                So it means that with Qt 6.7 it is not added to resources automatically. So the question is how to add it to resources automatically as it is done with Qt < 6.7?
                Note: I can see the file is generated in both cases.

                Christian EhrlicherC Offline
                Christian EhrlicherC Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on last edited by Christian Ehrlicher
                #6

                @KejPi said in Translation does not work with Qt 6.7:

                So it means that with Qt 6.7 it is not added to resources automatically.

                Please iterate the resource with QDirIterator to see where it was added. I doubt it is not added at all. From your CMakeLists.txt I also don't see why they should be under "i18n" subdirectory.

                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
                • K Offline
                  K Offline
                  KejPi
                  wrote on last edited by KejPi
                  #7

                  They should be added according to documentation

                  Qt 6.5.3

                  ":/i18n"
                  ":/i18n/AbracaDABra_pl.qm"
                  ":/i18n/AbracaDABra_cs.qm"
                  ":/i18n/AbracaDABra_de.qm"
                  

                  Qt 6.7.0

                  ":/i18n"
                  ":/i18n/gui"
                  ":/i18n/gui/AbracaDABra_pl.qm"
                  ":/i18n/gui/AbracaDABra_cs.qm"
                  ":/i18n/gui/AbracaDABra_de.qm"
                  

                  So it is added in both cases but 6.7 adds subdirectory according to project structure (translation files are handled from CMakeLists.txt located in gui directory). It is probably correct behavior but it makes the code incompatible. I will solve it by compiler switch and make this topic as solved.

                  Thank you for your help!

                  1 Reply Last reply
                  3
                  • K KejPi has marked this topic as solved on

                  • Login

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