Skip to content

Commit

Permalink
Handle translations Qt 6.7 way
Browse files Browse the repository at this point in the history
  • Loading branch information
Ri0n committed May 1, 2024
1 parent a7224df commit 50a7228
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 32 deletions.
29 changes: 26 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
# -------------------------------------------------

cmake_minimum_required(VERSION 3.10.0)
set(CMAKE_CXX_STANDARD 17)

set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")
include(QtNoteMacro)
message(STATUS "Version: QtNote-${QTNOTE_VERSION}")
Expand All @@ -28,13 +30,34 @@ if (Qt${QT_DEFAULT_MAJOR_VERSION}Widgets_VERSION VERSION_LESS 5.10.0)
message(FATAL_ERROR "Minimum supported Qt5 version is 5.10!")
endif()

set(CMAKE_CXX_STANDARD 17)

if(UNIX AND NOT (APPLE OR HAIKU))
set(UNIXLIKE ON)
endif()

include(GNUInstallDirs)
set(I18N_TRANSLATED_LANGUAGES)
file(GLOB qtnote_TRS "${CMAKE_CURRENT_SOURCE_DIR}/qtnote_*.ts")
foreach(_LANG ${qtnote_TRS})
get_filename_component(_SHORT_LANG ${_LANG} NAME_WE)
string(REPLACE "@" "_" _SHORT_LANG ${_SHORT_LANG})
list(APPEND I18N_TRANSLATED_LANGUAGES ${_SHORT_LANG})
endforeach()
if(Qt${QT_DEFAULT_MAJOR_VERSION}Core_VERSION VERSION_LESS 6.3.0)
include(GNUInstallDirs)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)
if(WIN32 AND CMAKE_RUNTIME_OUTPUT_DIRECTORY STREQUAL "")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
endif()
set(USE_FOLDERS ON)
elseif(Qt${QT_DEFAULT_MAJOR_VERSION}Core_VERSION VERSION_LESS 6.7.0)
qt_standard_project_setup()
else()
qt_standard_project_setup(
I18N_TRANSLATED_LANGUAGES ${I18N_TRANSLATED_LANGUAGES}
I18N_SOURCE_LANGUAGE en
)
endif()
set(APP_NAME qtnote)
set(TRANSLATIONSDIR ${CMAKE_INSTALL_FULL_DATADIR}/${APP_NAME})
set(PLUGINSDIR ${CMAKE_INSTALL_FULL_LIBDIR}/${APP_NAME})
Expand Down
63 changes: 38 additions & 25 deletions langs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,45 @@ file(GLOB qtnote_TRS "${CMAKE_CURRENT_SOURCE_DIR}/qtnote_*.ts")

find_package(Qt${QT_DEFAULT_MAJOR_VERSION} COMPONENTS LinguistTools REQUIRED)

set(PROJECT_DIRS
${CMAKE_SOURCE_DIR}
${qtnotexe_SOURCE_DIR}
${libqtnote_SOURCE_DIR}
${plugins_SOURCE_DIR}
)

#update translations with: make lupdate
add_custom_target(lupdate)
foreach(_LANG ${qtnote_TRS})
get_filename_component(_SHORT_LANG ${_LANG} NAME_WE)
string(REPLACE "@" "_" _SHORT_LANG ${_SHORT_LANG})
add_custom_command(TARGET lupdate
PRE_BUILD
COMMAND ${Qt${QT_DEFAULT_MAJOR_VERSION}_LUPDATE_EXECUTABLE}
ARGS -no-obsolete -recursive ${PROJECT_DIRS} -ts ${_LANG}
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
VERBATIM
if(Qt${QT_DEFAULT_MAJOR_VERSION}LinguistTools_VERSION VERSION_LESS 6.7.0)
set(PROJECT_DIRS
${CMAKE_SOURCE_DIR}
${qtnotexe_SOURCE_DIR}
${libqtnote_SOURCE_DIR}
${plugins_SOURCE_DIR}
)
endforeach()

if(WIN32)
set_source_files_properties(${qtnote_TRS} PROPERTIES OUTPUT_LOCATION "${EXECUTABLE_OUTPUT_PATH}/langs")
endif()
qt_add_translation(qtnote_QM ${qtnote_TRS})
#update translations with: make lupdate
add_custom_target(lupdate)
foreach(_LANG ${qtnote_TRS})
get_filename_component(_SHORT_LANG ${_LANG} NAME_WE)
string(REPLACE "@" "_" _SHORT_LANG ${_SHORT_LANG})
add_custom_command(TARGET lupdate
PRE_BUILD
COMMAND ${Qt${QT_DEFAULT_MAJOR_VERSION}_LUPDATE_EXECUTABLE}
ARGS -no-obsolete -recursive ${PROJECT_DIRS} -ts ${_LANG}
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
VERBATIM
)
endforeach()

add_custom_target(build_translations ALL DEPENDS ${qtnote_QM})
if(WIN32)
set_source_files_properties(${qtnote_TRS} PROPERTIES OUTPUT_LOCATION "${EXECUTABLE_OUTPUT_PATH}/langs")
endif()
qt_add_translation(qtnote_QM ${qtnote_TRS})

install(FILES ${qtnote_QM} DESTINATION ${TRANSLATIONSDIR} COMPONENT Executable)
add_custom_target(build_translations ALL DEPENDS ${qtnote_QM})
else()
set(LANGS_SOURCE_TARGETS)
foreach(trg baseintegration gnome kdeintegration spellchecker tomboy macosx)
if(TARGET ${trg})
list(APPEND LANGS_SOURCE_TARGETS ${trg})
endif()
endforeach()
qt_add_translations(TARGETS qtnoteexe
SOURCE_TARGETS qtnoteexe qtnote ${LANGS_SOURCE_TARGETS}
TS_FILE_BASE qtnote
TS_FILES ${qtnote_TRS}
QM_FILES_OUTPUT_VARIABLE qtnote_QM)
endif()
add_custom_target(build_translations ALL DEPENDS ${qtnote_QM})
4 changes: 0 additions & 4 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ cmake_minimum_required(VERSION 3.10.0)
include(QtNoteMacro)
project(qtnoteexe VERSION ${QTNOTE_VERSION} LANGUAGES CXX)

set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)

if(WIN32)
set(WINRESFILE "win/qtnote.rc")
endif()
Expand Down

0 comments on commit 50a7228

Please sign in to comment.