How to specify output name for qt5_add_translation?

时间:2017-12-18 06:29:16

标签: qt cmake translation qt-linguist

I want to generate a plenty *.qm for plenty *.ts files for different languages using qt5_add_translation. All the *.ts files are named using *.de_DE.ts/*.fr_FR.ts/etc convention. But qt5_add_translation produce output, using only basename until first ., not the last one.

There is no possibility to pass options to lrelease using qt5_add_translation(QM_FILES "${PROJECT_NAME}.de_DE.ts" OPTIONS -qm "${PROJECT_NAME}.de_DE.qm") syntax.

Also setting OUTPUT_NAME property for source *.ts file is not working:

set_source_files_properties(
    "${PROJECT_NAME}.de_DE.ts" PROPERTIES
    OUTPUT_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}"
    OUTPUT_NAME "${PROJECT_NAME}.de_DE.qm"
    )

Producing filename in the case is still "${PROJECT_NAME}.qm", not "${PROJECT_NAME}.de_DE.qm"

How to override producing name for resulting *.qm file?

Surely I can make custom command and use it for my purposes, but I prefer to use ready qt5_add_translation.

EDIT:

Looking at /usr/local/Qt-5.9.2/lib/cmake/Qt5LinguistTools/Qt5LinguistToolsMacros.cmake I conclude, that there is no way to achieve desired using ready to use qt5_add_translation, because of using get_filename_component(qm ${_abs_FILE} NAME_WE) to get filename:

NAME_WE = File name without directory or longest extension

For my purposes there is need to use combination of ABSOLUTE (to get filename w/ full suffix), then to apply multiple times EXT in combination with NAME_WE to extract filename w/o shortest extension.

2 个答案:

答案 0 :(得分:1)

I ended up with the below custom function List<pojo> list = calendarmstrDG.Items.OfType<pojo>().ToList(); to replace add_translation:

qt5_add_translation

It accepts basenames of function(ADD_TRANSLATION _qm_files) foreach(_basename ${ARGN}) set(qm "${CMAKE_CURRENT_SOURCE_DIR}/${_basename}.qm") add_custom_command( OUTPUT "${qm}" COMMAND "${Qt5_LRELEASE_EXECUTABLE}" ARGS -markuntranslated "Not translated!" -nounfinished -removeidentical -compress "${CMAKE_CURRENT_SOURCE_DIR}/${_basename}.ts" -qm "${qm}" DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/${_basename}.ts" VERBATIM ) list(APPEND ${_qm_files} "${qm}") endforeach() set(${_qm_files} ${${_qm_files}} PARENT_SCOPE) endfunction() files and produces list of resulting *.ts files: both in current source directory.

答案 1 :(得分:0)

请升级到Qt 5.9.4或更高版本。名称中带有圆点的.ts文件的处理已在此处进行了固定,另请参见https://bugreports.qt.io/browse/QTBUG-64317