Correct workflow for CMake + Qt translation system

I recently translated my Qt qmake project into the CMake build system, and now I'm trying to set up a translation system. I tried using the macro qt5_create_translation(registered here ) to update my * .ts files and generate * .qm files. By default, the macro creates (or updates) * .ts files in the source directory and * .qm files in the assembly directory, which is quite logical and convenient to use. The nature of the basic utility lupdateis such that * .ts files cannot be destroyed - they can only be updated. Therefore, I see my workflow as follows:

  • Add or modify source or user files.
  • Rebuild project: new translatable lines will be added to * .ts.
  • Add actual translations to * .ts now or commit the changes "as is" to add translations later.
  • Once translations are added to * .ts, rebuild the project to get updated * .qm files.

With this * .ts workflow file, files are almost always synchronized with the source files, and * .qm files are generated each time a project is created. But the ideology of the CMake plug-in and / or Qt5 for CMake follows differently. CMake rightly holds * .ts file accounts as build artifacts, so it generates a rule to delete them (from the source tree (!)) On make clean. This behavior was at least tw ice , registered as a bug, but the developers seem to insist that this is not a bug, but a function.

I found advice to add a subdirectory with translations to it and CLEAN_NO_CUSTOM, but these modifications disrupt the assembly: adding a * .qm file to an executable target do not add the subdirectory to the executable dependency list. Therefore assembly assembly does not find * .qm files and stops.

Adding a custom CMake target and / or calling a command lupdateoverrides all the benefits of a module Qt5LinguistToolsand a macro qt5_create_translation.

Adding the CMake option, for example here , looks like an ugly workaround and does not prevent the developer from losing an uncommitted translation by accidental invocation make cleanwhen UPDATE_TRANSLATIONSenabled.

So what is the correct way to use a macro qt5_create_translationwith its current behavior?

+4
1

do ADD_SUBDIRECTORY,

SET_DIRECTORY_PROPERTIES(PROPERTIES CLEAN_NO_CUSTOM TRUE)

QT5_CREATE_TRANSLATION
0

All Articles