[英]A proper workflow for CMake + Qt translation system
I recently moved my Qt project form qmake to CMake build system and now I'm trying to set up a translation system. 我最近将我的Qt项目从qmake转移到CMake构建系统,现在我正在尝试建立一个翻译系统。 I tried to use
qt5_create_translation
macro (documented here ) to update my *.ts files and generate *.qm files. 我尝试使用
qt5_create_translation
宏( 此处记录 )来更新我的* .ts文件并生成* .qm文件。 By default the macro creates (or updates) *.ts files in the source directory and *.qm files in the build directory, which is pretty logical and convenient to use. 默认情况下,宏在源目录中创建(或更新)* .ts文件,在构建目录中创建* .qm文件,这非常合乎逻辑且方便使用。 The nature of underlying
lupdate
utility is such that *.ts files cannot be destroyed - they may be updated only. 底层
lupdate
实用程序的本质是* .ts文件无法销毁 - 它们可能只是更新。 So I see my workflow as follows: 所以我看到我的工作流程如下:
With this workflow *.ts files are almost always synchronized with source files and *.qm files are generated every time you build the project. 使用此工作流* .ts文件几乎总是与源文件同步,每次构建项目时都会生成* .qm文件。 But the ideology of CMake and/or Qt5 plugin for CMake follows another way.
但CMake的CMake和/或Qt5插件的意识形态则采用另一种方式。 CMake rightly accounts *.ts files as build artifacts, so it generates a rule to delete them (from source tree (!)) on
make clean
. CMake正确地将* .ts文件视为构建工件,因此它会生成一条规则以在
make clean
上删除它们(来自源树(!))。 This behavior was at least tw ice registered as a bug, but maintainers seem to insist it's not a bug, but a feature. 这种行为至少是TW 冰注册为一个bug,但维护似乎坚持认为,这不是一个错误,而是一个功能。
I found an advice to add a subdirectory with translations and CLEAN_NO_CUSTOM
on it, but these modifications break the build: adding *.qm file to executable target does not add the subdirectory to executable dependency list. 我找到了一个建议 ,添加一个带有翻译和
CLEAN_NO_CUSTOM
的子目录,但是这些修改会破坏构建:将* .qm文件添加到可执行目标不会将子目录添加到可执行依赖项列表中。 So build build fails to find *.qm files and stops. 因此构建版本无法找到* .qm文件并停止。
Adding custom CMake target and\\or command invoking lupdate
derogates all advantages of Qt5LinguistTools
module and qt5_create_translation
macro. 添加自定义CMake的目标和\\或调用命令
lupdate
减损的所有优点Qt5LinguistTools
模块和qt5_create_translation
宏。
Adding a CMake option like here looks like an ugly workaround and does not keep the developer from loosing uncommitted translation by accidental invocation of make clean
when UPDATE_TRANSLATIONS
is turned on. 像这里添加一个CMake选项看起来像一个丑陋的解决方法,并且当
UPDATE_TRANSLATIONS
打开时,不会让开发人员因意外调用make clean
失去未提交的翻译。
So what is the proper way to use qt5_create_translation
macro with it's present-day behavior? 那么将
qt5_create_translation
宏与其当前行为一起使用的正确方法是什么?
without do ADD_SUBDIRECTORY
, 没有
do ADD_SUBDIRECTORY
,
I just add SET_DIRECTORY_PROPERTIES(PROPERTIES CLEAN_NO_CUSTOM TRUE)
我只是添加了
SET_DIRECTORY_PROPERTIES(PROPERTIES CLEAN_NO_CUSTOM TRUE)
before calling 在打电话之前
QT5_CREATE_TRANSLATION
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.