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. How to use the QtLinguist, easy way?
QtWS25 Last Chance

How to use the QtLinguist, easy way?

Scheduled Pinned Locked Moved Unsolved General and Desktop
qtlinguistcmakewindows
18 Posts 5 Posters 2.7k Views
  • 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.
  • A Offline
    A Offline
    Artem Shapovalov
    wrote on 12 Jul 2023, 05:01 last edited by
    #1

    Hi everyone!
    I have the cmake based project and trying to get multilinguage feature.
    In CMakeLists.txt I placed next lines:

    find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS LinguistTools)
    ...
    qt_add_translations(<my project name> TS_FILES <my project name>_de.ts)
    

    I got several errors, but now trying to solve the first of it:

    C:\Qt\6.5.1\mingw_64\lib\cmake\Qt6LinguistTools\Qt6LinguistToolsMacros.cmake:221: warning: Translation file 'C:/prj/<my project folder>/<my project name>_de.ts' does not exist.  Consider building the target '<my project name>_lupdate' to create an initial version of that file. C:/Qt/6.5.1/mingw_64/lib/cmake/Qt6LinguistTools/Qt6LinguistToolsMacros.cmake:333 (qt6_add_lrelease) C:/Qt/6.5.1/mingw_64/lib/cmake/Qt6LinguistTools/Qt6LinguistToolsMacros.cmake:389 (qt6_add_translations) CMakeLists.txt:45 (qt_add_translations)
    

    I searched the internet for a way to make it using the QtCreator, but no one works. I can't make new build target properly, Tools->External->Linguist->Update translations (lupdate) won't work too and produce next error:

    Starting external tool "C:\Qt\6.5.1\mingw_64\bin\lupdate.exe C:/prj/<my project folder>/CMakeLists.txt"
    lupdate error: Passing a CMakeLists.txt as project file is not supported.
    Please use the 'qt_add_lupdate' CMake command and build the 'update_translations' target.
    

    I thought that the 'qt_add_translations' macro expands with 'qt_add_lupdate' too.

    Does anyone know the proper way to use QtLinguist and internationalization? Or may be somebody know how to make the minimum working example?

    J 1 Reply Last reply 12 Jul 2023, 05:09
    1
    • A Artem Shapovalov
      12 Jul 2023, 05:01

      Hi everyone!
      I have the cmake based project and trying to get multilinguage feature.
      In CMakeLists.txt I placed next lines:

      find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS LinguistTools)
      ...
      qt_add_translations(<my project name> TS_FILES <my project name>_de.ts)
      

      I got several errors, but now trying to solve the first of it:

      C:\Qt\6.5.1\mingw_64\lib\cmake\Qt6LinguistTools\Qt6LinguistToolsMacros.cmake:221: warning: Translation file 'C:/prj/<my project folder>/<my project name>_de.ts' does not exist.  Consider building the target '<my project name>_lupdate' to create an initial version of that file. C:/Qt/6.5.1/mingw_64/lib/cmake/Qt6LinguistTools/Qt6LinguistToolsMacros.cmake:333 (qt6_add_lrelease) C:/Qt/6.5.1/mingw_64/lib/cmake/Qt6LinguistTools/Qt6LinguistToolsMacros.cmake:389 (qt6_add_translations) CMakeLists.txt:45 (qt_add_translations)
      

      I searched the internet for a way to make it using the QtCreator, but no one works. I can't make new build target properly, Tools->External->Linguist->Update translations (lupdate) won't work too and produce next error:

      Starting external tool "C:\Qt\6.5.1\mingw_64\bin\lupdate.exe C:/prj/<my project folder>/CMakeLists.txt"
      lupdate error: Passing a CMakeLists.txt as project file is not supported.
      Please use the 'qt_add_lupdate' CMake command and build the 'update_translations' target.
      

      I thought that the 'qt_add_translations' macro expands with 'qt_add_lupdate' too.

      Does anyone know the proper way to use QtLinguist and internationalization? Or may be somebody know how to make the minimum working example?

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 12 Jul 2023, 05:09 last edited by
      #2

      @Artem-Shapovalov said in How to use the QtLinguist, easy way?:

      Consider building the target '<my project name>_lupdate' to create an initial version of that file

      Did you do this?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      A 1 Reply Last reply 12 Jul 2023, 05:25
      0
      • J jsulm
        12 Jul 2023, 05:09

        @Artem-Shapovalov said in How to use the QtLinguist, easy way?:

        Consider building the target '<my project name>_lupdate' to create an initial version of that file

        Did you do this?

        A Offline
        A Offline
        Artem Shapovalov
        wrote on 12 Jul 2023, 05:25 last edited by
        #3

        @jsulm yeah, I tried, but with no result. In msys2 shell I cd to project's directory and tried to execute:

        cmake --build . --target <my project name>_lupdate
        

        and got and error:

        Error: could not load cache
        

        I'm not so profeccient in CMake and also I'm not sure that it's a proper way to build something because QtCreator is IDE with its own settings and variables that passed to the CMake. It's look strange to make IDE's job with external tools manually.

        J 1 Reply Last reply 12 Jul 2023, 05:26
        0
        • A Artem Shapovalov
          12 Jul 2023, 05:25

          @jsulm yeah, I tried, but with no result. In msys2 shell I cd to project's directory and tried to execute:

          cmake --build . --target <my project name>_lupdate
          

          and got and error:

          Error: could not load cache
          

          I'm not so profeccient in CMake and also I'm not sure that it's a proper way to build something because QtCreator is IDE with its own settings and variables that passed to the CMake. It's look strange to make IDE's job with external tools manually.

          J Offline
          J Offline
          jsulm
          Lifetime Qt Champion
          wrote on 12 Jul 2023, 05:26 last edited by
          #4

          @Artem-Shapovalov said in How to use the QtLinguist, easy way?:

          msys2

          Why msys2? You should use MinGW and its terminal provided with Qt.

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          A 1 Reply Last reply 12 Jul 2023, 05:37
          0
          • J jsulm
            12 Jul 2023, 05:26

            @Artem-Shapovalov said in How to use the QtLinguist, easy way?:

            msys2

            Why msys2? You should use MinGW and its terminal provided with Qt.

            A Offline
            A Offline
            Artem Shapovalov
            wrote on 12 Jul 2023, 05:37 last edited by
            #5

            @jsulm I have a Qt Creator 10.0.2. Where can I find this feature? I searched in Qt/Tools/mingw directory and didn't find any terminal application, just toolchain and some libraries and header files placed in linux-fashioned directory tree. I tried to open in QtCreator forlder in command prompt but it opens windows's cmd.exe in the project folder and this doesn't work with cmake.

            J 1 Reply Last reply 12 Jul 2023, 05:38
            0
            • A Artem Shapovalov
              12 Jul 2023, 05:37

              @jsulm I have a Qt Creator 10.0.2. Where can I find this feature? I searched in Qt/Tools/mingw directory and didn't find any terminal application, just toolchain and some libraries and header files placed in linux-fashioned directory tree. I tried to open in QtCreator forlder in command prompt but it opens windows's cmd.exe in the project folder and this doesn't work with cmake.

              J Offline
              J Offline
              jsulm
              Lifetime Qt Champion
              wrote on 12 Jul 2023, 05:38 last edited by
              #6

              @Artem-Shapovalov said in How to use the QtLinguist, easy way?:

              didn't find any terminal application

              If you installed Qt for MinGW you will find it in Windows start menu.
              So, what exact Qt version did you install?

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              A 1 Reply Last reply 12 Jul 2023, 05:56
              0
              • J jsulm
                12 Jul 2023, 05:38

                @Artem-Shapovalov said in How to use the QtLinguist, easy way?:

                didn't find any terminal application

                If you installed Qt for MinGW you will find it in Windows start menu.
                So, what exact Qt version did you install?

                A Offline
                A Offline
                Artem Shapovalov
                wrote on 12 Jul 2023, 05:56 last edited by
                #7

                @jsulm I download the installer qt-unified-windows-x64-4.6.0-online.exe. I search in start menu and found Qt 6.5.1 (MinGW 11.2.0 64-bit) shortcut. Launched it, cd to project's directory and tried to run:

                cmake --build . --target <my project name>_lupdate
                

                and got an error:

                'cmake' is not recognized as an internal or external command, operable program or batch file
                

                Seems to be it's not configured well and looks like standard windows cmd.exe. May be I should set it up manually before use?

                J 1 Reply Last reply 12 Jul 2023, 05:59
                0
                • A Artem Shapovalov
                  12 Jul 2023, 05:56

                  @jsulm I download the installer qt-unified-windows-x64-4.6.0-online.exe. I search in start menu and found Qt 6.5.1 (MinGW 11.2.0 64-bit) shortcut. Launched it, cd to project's directory and tried to run:

                  cmake --build . --target <my project name>_lupdate
                  

                  and got an error:

                  'cmake' is not recognized as an internal or external command, operable program or batch file
                  

                  Seems to be it's not configured well and looks like standard windows cmd.exe. May be I should set it up manually before use?

                  J Offline
                  J Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on 12 Jul 2023, 05:59 last edited by
                  #8

                  @Artem-Shapovalov said in How to use the QtLinguist, easy way?:

                  May be I should set it up manually before use?

                  No, the shortcut in the Start menu should be fine. Maybe path to cmake executable is not configured automatically, but you can still use absolute path to cmake.exe.

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  A 1 Reply Last reply 12 Jul 2023, 06:07
                  0
                  • J jsulm
                    12 Jul 2023, 05:59

                    @Artem-Shapovalov said in How to use the QtLinguist, easy way?:

                    May be I should set it up manually before use?

                    No, the shortcut in the Start menu should be fine. Maybe path to cmake executable is not configured automatically, but you can still use absolute path to cmake.exe.

                    A Offline
                    A Offline
                    Artem Shapovalov
                    wrote on 12 Jul 2023, 06:07 last edited by
                    #9

                    @jsulm I tried to run:

                    C:\<path to cmake from Qt\cmake.exe --build . --target <my project name>_lupdate
                    

                    and got an error:

                    Error: could not load cache
                    

                    What should I do before the build this target?

                    kkoehneK 1 Reply Last reply 12 Jul 2023, 07:11
                    0
                    • A Artem Shapovalov
                      12 Jul 2023, 06:07

                      @jsulm I tried to run:

                      C:\<path to cmake from Qt\cmake.exe --build . --target <my project name>_lupdate
                      

                      and got an error:

                      Error: could not load cache
                      

                      What should I do before the build this target?

                      kkoehneK Offline
                      kkoehneK Offline
                      kkoehne
                      Moderators
                      wrote on 12 Jul 2023, 07:11 last edited by
                      #10

                      @Artem-Shapovalov

                      Have you navigated to the build directory of the project (displayed in Qt Creator under Projects > Build Settings > Build Directory)?

                      Anyhow, if you don't feel confident on the command line, you can also trigger the target from within Qt Creator: Press Ctrl+K (to open the navigator), and then type

                      cm <my project name>_lupdate
                      

                      Director R&D, The Qt Company

                      A ekkescornerE 2 Replies Last reply 12 Jul 2023, 07:19
                      1
                      • kkoehneK kkoehne
                        12 Jul 2023, 07:11

                        @Artem-Shapovalov

                        Have you navigated to the build directory of the project (displayed in Qt Creator under Projects > Build Settings > Build Directory)?

                        Anyhow, if you don't feel confident on the command line, you can also trigger the target from within Qt Creator: Press Ctrl+K (to open the navigator), and then type

                        cm <my project name>_lupdate
                        
                        A Offline
                        A Offline
                        Artem Shapovalov
                        wrote on 12 Jul 2023, 07:19 last edited by
                        #11

                        @kkoehne I checked this feature and it's don't build unknown targets.

                        @kkoehne , @jsulm , thank you guys, I explore a little bit more, but I decided to use another internationalization tool. Maybe later I would return to this Qt feature.

                        kkoehneK 1 Reply Last reply 12 Jul 2023, 07:42
                        0
                        • A Artem Shapovalov
                          12 Jul 2023, 07:19

                          @kkoehne I checked this feature and it's don't build unknown targets.

                          @kkoehne , @jsulm , thank you guys, I explore a little bit more, but I decided to use another internationalization tool. Maybe later I would return to this Qt feature.

                          kkoehneK Offline
                          kkoehneK Offline
                          kkoehne
                          Moderators
                          wrote on 12 Jul 2023, 07:42 last edited by
                          #12

                          @Artem-Shapovalov said in How to use the QtLinguist, easy way?:

                          @kkoehne I checked this feature and it's don't build unknown targets.

                          THat's weird. If the target is 'unknown', then it doesn't exist in CMake, I'd claim.

                          @kkoehne , @jsulm , thank you guys, I explore a little bit more, but I decided to use
                          another internationalization tool. Maybe later I would return to this Qt feature.

                          Out of interest: Which tool are you going for?

                          Director R&D, The Qt Company

                          A 1 Reply Last reply 12 Jul 2023, 08:03
                          0
                          • kkoehneK kkoehne
                            12 Jul 2023, 07:42

                            @Artem-Shapovalov said in How to use the QtLinguist, easy way?:

                            @kkoehne I checked this feature and it's don't build unknown targets.

                            THat's weird. If the target is 'unknown', then it doesn't exist in CMake, I'd claim.

                            @kkoehne , @jsulm , thank you guys, I explore a little bit more, but I decided to use
                            another internationalization tool. Maybe later I would return to this Qt feature.

                            Out of interest: Which tool are you going for?

                            A Offline
                            A Offline
                            Artem Shapovalov
                            wrote on 12 Jul 2023, 08:03 last edited by
                            #13

                            @kkoehne I write my own. Less than 100 lines of code, but at present moment cover all of my needs.

                            1 Reply Last reply
                            0
                            • kkoehneK kkoehne
                              12 Jul 2023, 07:11

                              @Artem-Shapovalov

                              Have you navigated to the build directory of the project (displayed in Qt Creator under Projects > Build Settings > Build Directory)?

                              Anyhow, if you don't feel confident on the command line, you can also trigger the target from within Qt Creator: Press Ctrl+K (to open the navigator), and then type

                              cm <my project name>_lupdate
                              
                              ekkescornerE Offline
                              ekkescornerE Offline
                              ekkescorner
                              Qt Champions 2016
                              wrote on 22 Nov 2023, 11:31 last edited by ekkescorner
                              #14

                              @kkoehne now I'm fighting with this. just ported all my apps from 5.15 to 6.6 using QMake.
                              Now as next step: port from QMake to CMake
                              BTW: doing it all from inside QtCreator, no cmdline
                              all my apps rely on translations and this works well in 5.15/QMake:
                              changed strings - build project - external cmd lupdate - QtLinguist - extrernal cmd lrelease
                              External commands don't work as reported here.
                              tried with QtCreator Linguist Example arrowpad

                              qt6_add_translations(arrowpad
                                  TS_FILES arrowpad_fr.ts arrowpad_nl.ts 
                                  QM_FILES_OUTPUT_VARIABLE qm_files)
                              install(FILES ${qm_files} DESTINATION ${INSTALL_EXAMPLEDIR})
                              

                              added arrowpad_de.ts, saved CMakeLists.txt and the file was created.
                              build the project, but all .ts files are empty
                              tried your recommendation:

                              cm arrowpad_lupdate
                              

                              doesnt work. while typing (macOS) Cmd-Kcm arrowpad there's only arrowpad_lrelease listed but no arrowpad_lupdate
                              any idea ?

                              ekke ... Qt Champion 2016 | 2024 ... mobile business apps
                              5.15 --> 6.8 https://t1p.de/ekkeChecklist
                              QMake --> CMake https://t1p.de/ekkeCMakeMobileApps

                              kkoehneK 1 Reply Last reply 22 Nov 2023, 11:41
                              0
                              • ekkescornerE ekkescorner
                                22 Nov 2023, 11:31

                                @kkoehne now I'm fighting with this. just ported all my apps from 5.15 to 6.6 using QMake.
                                Now as next step: port from QMake to CMake
                                BTW: doing it all from inside QtCreator, no cmdline
                                all my apps rely on translations and this works well in 5.15/QMake:
                                changed strings - build project - external cmd lupdate - QtLinguist - extrernal cmd lrelease
                                External commands don't work as reported here.
                                tried with QtCreator Linguist Example arrowpad

                                qt6_add_translations(arrowpad
                                    TS_FILES arrowpad_fr.ts arrowpad_nl.ts 
                                    QM_FILES_OUTPUT_VARIABLE qm_files)
                                install(FILES ${qm_files} DESTINATION ${INSTALL_EXAMPLEDIR})
                                

                                added arrowpad_de.ts, saved CMakeLists.txt and the file was created.
                                build the project, but all .ts files are empty
                                tried your recommendation:

                                cm arrowpad_lupdate
                                

                                doesnt work. while typing (macOS) Cmd-Kcm arrowpad there's only arrowpad_lrelease listed but no arrowpad_lupdate
                                any idea ?

                                kkoehneK Offline
                                kkoehneK Offline
                                kkoehne
                                Moderators
                                wrote on 22 Nov 2023, 11:41 last edited by kkoehne
                                #15

                                @ekkescorner , have you actually tried running

                                cm arrowpad_lupdate
                                

                                from Qt Creator? For me the command never shows up in autocomplete (which needs to be studied, created https://bugreports.qt.io/browse/QTCREATORBUG-29946), but I can run it, with Qt 6.6.0.

                                Director R&D, The Qt Company

                                ekkescornerE 1 Reply Last reply 22 Nov 2023, 11:52
                                1
                                • kkoehneK kkoehne
                                  22 Nov 2023, 11:41

                                  @ekkescorner , have you actually tried running

                                  cm arrowpad_lupdate
                                  

                                  from Qt Creator? For me the command never shows up in autocomplete (which needs to be studied, created https://bugreports.qt.io/browse/QTCREATORBUG-29946), but I can run it, with Qt 6.6.0.

                                  ekkescornerE Offline
                                  ekkescornerE Offline
                                  ekkescorner
                                  Qt Champions 2016
                                  wrote on 22 Nov 2023, 11:52 last edited by
                                  #16

                                  @kkoehne aaah. typing it it's working. was confused because autocomplete missed it.
                                  THX - no I can go on to the next CMake features :)

                                  ekke ... Qt Champion 2016 | 2024 ... mobile business apps
                                  5.15 --> 6.8 https://t1p.de/ekkeChecklist
                                  QMake --> CMake https://t1p.de/ekkeCMakeMobileApps

                                  1 Reply Last reply
                                  0
                                  • A Offline
                                    A Offline
                                    Adaita Kumar Behera
                                    wrote on 12 May 2024, 08:51 last edited by Adaita Kumar Behera 5 Dec 2024, 08:54
                                    #17

                                    I was struggling with the same issue and I landed here. It helped. Now, I made the following changes to my cmake script to make it seamless.

                                    add_custom_target(run_app_lupdate
                                    COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target app_lupdate
                                    COMMENT "Running app_lupdate"
                                    )
                                    add_dependencies(app run_app_lupdate)

                                    Here "app' is the traget name

                                    1 Reply Last reply
                                    0
                                    • ekkescornerE Offline
                                      ekkescornerE Offline
                                      ekkescorner
                                      Qt Champions 2016
                                      wrote on 12 May 2024, 09:49 last edited by
                                      #18

                                      you don't need this. Qt 6.7 / QtC 13.0:
                                      there are automatically generated targets there, you can execute:
                                      update_translations
                                      release_translations

                                      cm_update_translations

                                      ekke ... Qt Champion 2016 | 2024 ... mobile business apps
                                      5.15 --> 6.8 https://t1p.de/ekkeChecklist
                                      QMake --> CMake https://t1p.de/ekkeCMakeMobileApps

                                      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