Results 1 to 3 of 3

Thread: How to do translation with a CMake project?

  1. #1
    Join Date
    Nov 2014
    Posts
    35
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default How to do translation with a CMake project?

    Hello,

    I am developing an application with Qt 5.3, generating the project files with CMake and building with Visual Studio 2013.

    Now I need to start working on the translation of the software, but I am kind of lost on how to do this with a CMake project.

    I found some info in the Qt CMake manual on the Qt5LinguistTools, I added the macros to my CMake, but I don't know when are the qm and ts files generated, or how I am supposed to add them to the project.

    I added the FIND_PACKAGE macro:
    SET ( Qt5LinguistTools_DIR "C:/Qt/5.3.2/vs2013_64bits/qtbase/lib/cmake/Qt5LinguistTools" CACHE PATH "Qt5LinguistTools_DIR" )
    FIND_PACKAGE( Qt5LinguistTools )

    I added the QT5_CREATE_TRANSLATION macro:
    QT5_CREATE_TRANSLATION( QT_TRANSLATIONS_FILES ${MOC_HEADER_FILES} ${QT_SOURCE_FILES} )

    And finally I added the QT5_ADD_TRANSLATION macro:
    QT5_ADD_TRANSLATION( QT_TRANSLATIONS_FILES )

    But after configuring and generating the CMake build project, and opening and building in Visual Studio, I don't see anything new or different.

    Am I doing this right? Am I supposed to add some files as sources in the ADD_EXECUTABLE macro?

    Any help will be greatly appreciated! Thanks!
    pixaeiro
    http://www.pixaflux.com
    Non-destructive Image Editor

  2. #2
    Join Date
    Jul 2017
    Posts
    37
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: How to do translation with a CMake project?

    I've been looking for the way to do this in CMake. I find pages that were written years ago saying that the capability to add custom build rules is intentionally disabled in CMake, for reasons unexplained, with no explanation how to enable it. It looks like the way to do it is:
    1. List all .ts files in the source directory.
    2. Run the list through sed, changing the source directory to the build directory and the extension to .qm .
    3. Run the CMake add_custom_command command on each .qm file (whether it exists or not), telling it that it can be made by running lrelease on the corresponding .ts file.
    As to updating the .ts files, they are source files which have to be manually edited by translators, so they can't be updated by CMake. Use a shell script that just does "lupdate *.cpp -ts *.ts".

  3. #3
    Join Date
    Oct 2012
    Posts
    132
    Thanks
    10
    Thanked 21 Times in 21 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: How to do translation with a CMake project?

    You found the documentation? http://doc.qt.io/qt-5/cmake-manual.html

    Using the described macros makes adding further translations, updating existing translations and releasing them is quite simple.

    Using those macros, my projects only require extending a variable to add further translations: https://github.com/Martchus/syncthin...g-translations (CMake module were magic happens: https://github.com/Martchus/qtutilit...fig.cmake#L125)

    So there is no need to use a shell script for calling lupdate. My CMake module also adds install targets for the translations. It even allows to optionally include the translations as resources using the Qt resource system (so you don't have extra files flying around your statically linked binary).
    Last edited by Infinity; 18th July 2017 at 00:35.

Similar Threads

  1. qt creator with cmake project
    By cic in forum Qt Tools
    Replies: 1
    Last Post: 1st July 2014, 10:25
  2. How to convert QT Project to CMake project?
    By Kevin Hoang in forum Qt Programming
    Replies: 2
    Last Post: 29th March 2011, 10:48
  3. Openning a qt project using cmake
    By Hogwarts in forum Newbie
    Replies: 1
    Last Post: 23rd February 2011, 19:48
  4. build project with cmake does not work
    By codebehind in forum Qt Programming
    Replies: 4
    Last Post: 18th August 2008, 13:29
  5. Automatic translation in qmake's project?
    By mchara in forum Qt Programming
    Replies: 7
    Last Post: 11th July 2008, 16:11

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.