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. Can't translate Qt texts
Qt 6.11 is out! See what's new in the release blog

Can't translate Qt texts

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 4 Posters 1.9k 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.
  • Roy44R Offline
    Roy44R Offline
    Roy44
    wrote on last edited by
    #1

    Hi,

    I make an multi language application, then I use QTranslator.
    QFile dialog is not translated so I try to load qt_fr.qm like

    qtTranslator.load(":/translations/qt_fr.qm");
    

    return always false. (the file is in my qrc)
    (it works with my own translation file)

    QTranslator qtTranslator;
    qtTranslator.load("qt_" + QLocale::system().name(),
    QLibraryInfo::location(QLibraryInfo::TranslationsPath));
    app.installTranslator(&qtTranslator);
    

    works but only if Qt is installed.
    How can I fix this ?

    thanks,
    sorry fo my english.

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

      Hi,

      Might be a silly question but are you sure you are using the correct path to your resources translation file ?

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

        Hi,
        Yes, I had the same idea but even

        QTranslator qtTranslator;
            bool bLoaded = qtTranslator.load("C:/Qt/5.10.0/msvc2015/translations/qt_fr.qm");
            application.installTranslator(&qtTranslator);
        

        return false.

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

          You mean installTranslator returns false? Then you should check with QFileInfo (exits, isReadable)

          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
          • Roy44R Offline
            Roy44R Offline
            Roy44
            wrote on last edited by
            #5

            Yes I mean load return false.

            QFileInfo info("C:/Qt/5.10.0/msvc2015/translations/qt_fr.qm");
                bool bExist = info.exists();
                bool bReadable = info.isReadable();
            

            bExist and bReadable are true.
            The only explanation i see, is "C:/Qt/5.10.0/msvc2015/translations/qt_fr.qm" is not a correct qm file.
            So what's the difference between

            QTranslator qtTranslator;
            qtTranslator.load("qt_" + QLocale::system().name(),
            QLibraryInfo::location(QLibraryInfo::TranslationsPath));
            app.installTranslator(&qtTranslator);
            

            and

            QTranslator qtTranslator;
            qtTranslator.load("C:/Qt/5.10.0/msvc2015/translations/qt_fr.qm");
            app.installTranslator(&qtTranslator);
            

            both codes load the same file (in french OS)?

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

              Ah, you are using the load() function in a wrong way: http://doc.qt.io/qt-5/qtranslator.html#load
              --> const QString &filename, const QString &directory = QString() , at least this would be my next guess :)

              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
              2
              • Roy44R Offline
                Roy44R Offline
                Roy44
                wrote on last edited by
                #7

                it works if I do

                qtTranslator.load("qt_fr",  "C:/Qt/5.10.0/msvc2015/translations");
                

                but not for

                m_QtTranslator.load("qt_fr", ":/translations/qm");
                

                before compile my script copy .qm in the correct path. qt_ files are in my qrc but I can't load them...
                Do qt_*.qm need some other files ?
                sorry for my english

                J.HilkJ 1 Reply Last reply
                0
                • Roy44R Offline
                  Roy44R Offline
                  Roy44
                  wrote on last edited by
                  #8

                  I think qt_fr.qm does need other qm files, if I use only qtbase_fr.qm I have my translations.

                  1 Reply Last reply
                  0
                  • Roy44R Roy44

                    it works if I do

                    qtTranslator.load("qt_fr",  "C:/Qt/5.10.0/msvc2015/translations");
                    

                    but not for

                    m_QtTranslator.load("qt_fr", ":/translations/qm");
                    

                    before compile my script copy .qm in the correct path. qt_ files are in my qrc but I can't load them...
                    Do qt_*.qm need some other files ?
                    sorry for my english

                    J.HilkJ Online
                    J.HilkJ Online
                    J.Hilk
                    Moderators
                    wrote on last edited by J.Hilk
                    #9

                    hi @Roy44
                    did you do a complete clean/rebuild of your project after adding the qm files to your resources ?
                    IIRC the binary file qmake creates out of your ressource file is not updated automatically when you add new ressources, therefore the translation files may not be included in your executable.


                    Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                    Q: What's that?
                    A: It's blue light.
                    Q: What does it do?
                    A: It turns blue.

                    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