diff --git a/cmake/Modules/QbtTranslations.cmake b/cmake/Modules/QbtTranslations.cmake new file mode 100644 index 000000000..71966fa7d --- /dev/null +++ b/cmake/Modules/QbtTranslations.cmake @@ -0,0 +1,48 @@ +# macros to handle translation files + +# qbt_add_translations( QRC_FILE TS_FILES ) +# handles out of source builds for Qt resource files that include translations +# The function generates translations out of the supplied list of .ts files in the build directory, +# copies the .qrc file there, calls qt5_add_resources() adds its output to the target sources list. +function(qbt_add_translations _target) + set(oneValueArgs QRC_FILE) + set(multiValueArgs TS_FILES) + cmake_parse_arguments(QBT_TR "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + + get_target_property(_binaryDir ${_target} BINARY_DIR) + + if (NOT QBT_TR_QRC_FILE) + message(FATAL_ERROR "QRC file is empty") + endif() + if (NOT QBT_TR_TS_FILES) + message(FATAL_ERROR "TS_FILES files are empty") + endif() + + if(IS_ABSOLUTE "${QBT_TR_QRC_FILE}") + file(RELATIVE_PATH _qrcToTs "${CMAKE_CURRENT_SOURCE_DIR}" "${QBT_TR_QRC_FILE}") + else() + set(_qrcToTs "${QBT_TR_QRC_FILE}") + endif() + + get_filename_component(_qrcToTsDir "${_qrcToTs}" DIRECTORY) + + get_filename_component(_qmFilesBinaryDir "${CMAKE_CURRENT_BINARY_DIR}/${_qrcToTsDir}" ABSOLUTE) + # to make qt5_add_translation() work as we need + set_source_files_properties(${QBT_TR_TS_FILES} PROPERTIES OUTPUT_LOCATION "${_qmFilesBinaryDir}") + qt5_add_translation(_qmFiles ${QBT_TR_TS_FILES}) + + set(_qrc_dest_dir "${_binaryDir}/${_qrcToTsDir}") + set(_qrc_dest_file "${_binaryDir}/${QBT_TR_QRC_FILE}") + + message(STATUS "copying ${QBT_TR_QRC_FILE} to ${_qrc_dest_dir}") + file(COPY ${QBT_TR_QRC_FILE} DESTINATION ${_qrc_dest_dir}) + + set_source_files_properties("${_qrc_dest_file}" PROPERTIES + GENERATED True + OBJECT_DEPENDS "${_qmFiles}") + + # With AUTORCC enabled rcc is ran by cmake before language files are generated, + # and thus we call rcc explicitly + qt5_add_resources(_resources "${_qrc_dest_file}") + target_sources(${_target} PRIVATE "${_resources}") +endfunction() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 71435f360..c72229e1f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -13,7 +13,7 @@ if (Boost_VERSION VERSION_LESS 106000) add_definitions(-DBOOST_NO_CXX11_RVALUE_REFERENCES) endif() -find_package(Qt5 ${requiredQtVersion} REQUIRED COMPONENTS Core Network Xml) +find_package(Qt5 ${requiredQtVersion} REQUIRED COMPONENTS Core Network Xml LinguistTools) find_package(Qt5Widgets ${requiredQtVersion}) if (Qt5Widgets_FOUND) find_package(Qt5DBus ${requiredQtVersion}) diff --git a/src/app/CMakeLists.txt b/src/app/CMakeLists.txt index 3d397804a..4079dfe93 100644 --- a/src/app/CMakeLists.txt +++ b/src/app/CMakeLists.txt @@ -23,29 +23,19 @@ set_target_properties(qBittorrent ) # translations -file(GLOB QBT_TS_FILES ../lang/*.ts) -get_filename_component(QBT_QM_FILES_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/../lang" ABSOLUTE) -set_source_files_properties(${QBT_TS_FILES} PROPERTIES OUTPUT_LOCATION "${QBT_QM_FILES_BINARY_DIR}") - -find_package(Qt5 COMPONENTS LinguistTools REQUIRED) -qt5_add_translation(QBT_QM_FILES ${QBT_TS_FILES}) - -get_filename_component(_lang_qrc_src "${CMAKE_CURRENT_SOURCE_DIR}/../lang/lang.qrc" ABSOLUTE) -get_filename_component(_lang_qrc_dst "${CMAKE_CURRENT_BINARY_DIR}/../lang/lang.qrc" ABSOLUTE) -get_filename_component(_lang_qrc_dst_dir "${CMAKE_CURRENT_BINARY_DIR}/../lang" ABSOLUTE) +include(QbtTranslations) -message(STATUS "copying ${_lang_qrc_src} -> ${_lang_qrc_dst}") -file(COPY ${_lang_qrc_src} DESTINATION ${_lang_qrc_dst_dir}) +file(GLOB QBT_TS_FILES ../lang/*.ts) +qbt_add_translations(qBittorrent QRC_FILE "../lang/lang.qrc" TS_FILES ${QBT_TS_FILES}) -set_source_files_properties("${_lang_qrc_dst}" PROPERTIES GENERATED True) -foreach(qm_file ${QBT_QM_FILES}) - set_source_files_properties("${_lang_qrc_dst}" PROPERTIES OBJECT_DEPENDS ${qm_file}) -endforeach() +if (WEBUI) + file(GLOB QBT_WEBUI_TS_FILES ../webui/www/translations/*.ts) + qbt_add_translations(qBittorrent QRC_FILE "../webui/www/translations/webui_translations.qrc" TS_FILES ${QBT_WEBUI_TS_FILES}) +endif() set(QBT_APP_RESOURCES ../icons/icons.qrc ../searchengine/searchengine.qrc -"${_lang_qrc_dst}" ) # With AUTORCC rcc is ran by cmake before language files are generated, diff --git a/src/webui/webui.pri b/src/webui/webui.pri index bdf4aede3..73a146005 100644 --- a/src/webui/webui.pri +++ b/src/webui/webui.pri @@ -27,7 +27,7 @@ SOURCES += \ $$PWD/webapplication.cpp \ $$PWD/webui.cpp -RESOURCES += $$PWD/www/webui.qrc +RESOURCES += $$PWD/www/webui.qrc $$PWD/www/translations/webui_translations.qrc # WebUI Translation isEmpty(QMAKE_LRELEASE) { diff --git a/src/webui/www/translations/webui_translations.qrc b/src/webui/www/translations/webui_translations.qrc new file mode 100644 index 000000000..005f87246 --- /dev/null +++ b/src/webui/www/translations/webui_translations.qrc @@ -0,0 +1,54 @@ + + + webui_ar.qm + webui_be.qm + webui_bg.qm + webui_ca.qm + webui_cs.qm + webui_da.qm + webui_de.qm + webui_el.qm + webui_en.qm + webui_en_AU.qm + webui_en_GB.qm + webui_eo.qm + webui_es.qm + webui_eu.qm + webui_fi.qm + webui_fr.qm + webui_gl.qm + webui_he.qm + webui_hi_IN.qm + webui_hr.qm + webui_hu.qm + webui_hy.qm + webui_id.qm + webui_is.qm + webui_it.qm + webui_ja.qm + webui_ka.qm + webui_ko.qm + webui_lt.qm + webui_lv_LV.qm + webui_ms_MY.qm + webui_nb.qm + webui_nl.qm + webui_oc.qm + webui_pl.qm + webui_pt_BR.qm + webui_pt_PT.qm + webui_ro.qm + webui_ru.qm + webui_sk.qm + webui_sl.qm + webui_sr.qm + webui_sv.qm + webui_tr.qm + webui_uk.qm + webui_uz@Latn.qm + webui_vi.qm + webui_zh.qm + webui_zh_HK.qm + webui_zh_TW.qm + + diff --git a/src/webui/www/webui.qrc b/src/webui/www/webui.qrc index 572d352e6..6fc7a9670 100644 --- a/src/webui/www/webui.qrc +++ b/src/webui/www/webui.qrc @@ -45,55 +45,5 @@ public/css/login.css public/login.html public/scripts/lib/mootools-1.2-core-yc.js - translations/webui_ar.qm - translations/webui_be.qm - translations/webui_bg.qm - translations/webui_ca.qm - translations/webui_cs.qm - translations/webui_da.qm - translations/webui_de.qm - translations/webui_el.qm - translations/webui_en.qm - translations/webui_en_AU.qm - translations/webui_en_GB.qm - translations/webui_eo.qm - translations/webui_es.qm - translations/webui_eu.qm - translations/webui_fi.qm - translations/webui_fr.qm - translations/webui_gl.qm - translations/webui_he.qm - translations/webui_hi_IN.qm - translations/webui_hr.qm - translations/webui_hu.qm - translations/webui_hy.qm - translations/webui_id.qm - translations/webui_is.qm - translations/webui_it.qm - translations/webui_ja.qm - translations/webui_ka.qm - translations/webui_ko.qm - translations/webui_lt.qm - translations/webui_lv_LV.qm - translations/webui_ms_MY.qm - translations/webui_nb.qm - translations/webui_nl.qm - translations/webui_oc.qm - translations/webui_pl.qm - translations/webui_pt_BR.qm - translations/webui_pt_PT.qm - translations/webui_ro.qm - translations/webui_ru.qm - translations/webui_sk.qm - translations/webui_sl.qm - translations/webui_sr.qm - translations/webui_sv.qm - translations/webui_tr.qm - translations/webui_uk.qm - translations/webui_uz@Latn.qm - translations/webui_vi.qm - translations/webui_zh.qm - translations/webui_zh_HK.qm - translations/webui_zh_TW.qm