1

I'm developing Qt application and now I want to do some I18N stuff. First problem I meet is that cmake doesn't know about command QT5_ADD_TRANSLATION(we are using cmake for building our project). I refer to QtLinguist Manual. When I met that problem, I also read threads like Unknown CMake command "QT5_CREATE_TRANSLATION" and qt4 to qt5 migration, but unluckily, I still stuck here.

My cmake version is 3.16 for Qt 5.15.2. If you need more informations, please let me know.

Besides, If there is an alternative way to accomplish I18N work in Qt with cmake, that is also fine. For example, I come up with add_custom_command with lupdate from qt, but don't success yet.


add_custom_command(OUTPUT ${TRANSLATIONS}
                   DEPENDS ${SOURCES}
                   COMMAND lupdate)

command won't execute. I'm still try it.

taptiptop
  • 13
  • 6

1 Answers1

4

It should be something like this:

find_package(Qt5 COMPONENTS LinguistTools)
qt5_add_translation(OUTPUT_VAR your_translation.ts)

CMake functions/macros provided by Qt itself belong to some particular module so you need to find that module before using its functioncs.

ixSci
  • 13,100
  • 5
  • 45
  • 79
  • This solves my problem. Besides, I find this very helpful, https://gist.github.com/giraldeau/546ba5512a74dfe9d8ea0862d66db412 – taptiptop May 05 '22 at 13:20