本文介绍了Qt国际化和CMake:如何更新* .ts,不要丢失它们的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个 c>

解决方案 c> make clean 问题,添加一个子目录( ADD_SUBDIRECTORY(translations))并添加 SET_DIRECTORY_PROPERTIES(PROPERTIES CLEAN_NO_CUSTOM 1) 到包含的CMakeLists.txt。
请参见的示例。



对于问题的第二部分,有两种可能的方法。使用 FILE(WRITE< filename>QT5_CREATE_TRANSLATION(QM_FILES $ {SOURCE_DIR} / src / app $ {TRANSLATIONS} OPTIONS -I $ {SOURCE_DIR} / src))然后在add_custom_target中使用 COMMAND $ {CMAKE_COMMAND} -DSOURCE_DIR = $ {CMAKE_SOURCE_DIR} -DTRANSLATIONS = $ {TRANSLATIONS}< filename> 。我怀疑有一个很好的方法来检索QM_FILES的内容。
第二个选项是创建两个额外的子目录,每个子目录都有一个QT5_CREATE_TRANSLATIONS和一个ADD_CUSTOM_TARGET调用。


I'm having this CMakeLists.txt in directory with translation files (*.ts):

SET(TRANSLATIONS
    lang_de.ts
    lang_en.ts
)

FIND_PACKAGE(Qt5LinguistTools)
QT5_ADD_TRANSLATION(QM_FILES ${TRANSLATIONS})
SET(QM_FILES ${QM_FILES} PARENT_SCOPE)
ADD_CUSTOM_TARGET (translations ALL DEPENDS ${QM_FILES})

It builds *.qm files from specified *.ts.

But I want to improve this and get two custom targets, which won't built automatically.One for appending new strings from sources into ts files, and one for refreshing ts. The last one would update ts from sources and remove obsolete strings from ts.

I've tried to add this after lines above:

ADD_CUSTOM_TARGET (
    ts_append
    COMMAND QT5_CREATE_TRANSLATION(QM_FILES ${CMAKE_SOURCE_DIR}/src/app ${TRANSLATIONS} OPTIONS -I ${CMAKE_SOURCE_DIR}/src)
)

ADD_CUSTOM_TARGET (
    ts_refresh
    COMMAND QT5_CREATE_TRANSLATION(QM_FILES ${CMAKE_SOURCE_DIR}/src/app ${TRANSLATIONS} OPTIONS -no-obsolete -I ${CMAKE_SOURCE_DIR}/src)
)

but it seems I can't use QT5_CREATE_TRANSLATION macro inside custom target, isn't it?

Maybe I'm on wrong way, how would you solve this problem: easy updating of ts and don't lose them after make clean?

解决方案

To solve the make clean problem, add a sub directory (ADD_SUBDIRECTORY(translations)) and add SET_DIRECTORY_PROPERTIES(PROPERTIES CLEAN_NO_CUSTOM 1) to the contained CMakeLists.txt.See here for an example of that.

For the second part of your question there are two possible ways to do it. Either use FILE(WRITE <filename> "QT5_CREATE_TRANSLATION(QM_FILES ${SOURCE_DIR}/src/app ${TRANSLATIONS} OPTIONS -I ${SOURCE_DIR}/src)") and then use COMMAND ${CMAKE_COMMAND} -DSOURCE_DIR=${CMAKE_SOURCE_DIR} -DTRANSLATIONS=${TRANSLATIONS} <filename> in add_custom_target. I doubt there's a good way of retrieving the contents of QM_FILES though.The second option is creating two additional sub directories, each with a QT5_CREATE_TRANSLATIONS and a ADD_CUSTOM_TARGET call.

这篇关于Qt国际化和CMake:如何更新* .ts,不要丢失它们的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 05:51