mirror of
https://gitlab.linphone.org/BC/public/linphone-desktop.git
synced 2026-05-03 22:56:49 +00:00
Change translation update process (Fix for qt5.13)
This commit is contained in:
parent
61fc68693a
commit
9097ae1763
3 changed files with 58 additions and 38 deletions
|
|
@ -282,7 +282,6 @@ endfunction ()
|
|||
# Force absolute paths.
|
||||
PREPEND(SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/")
|
||||
PREPEND(HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/")
|
||||
PREPEND(QRC_RESOURCES "${CMAKE_CURRENT_SOURCE_DIR}/")
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Compute QML files list.
|
||||
|
|
@ -313,7 +312,7 @@ if (NOT WIN32)
|
|||
check_qml DEPENDS ${QML_SOURCES}
|
||||
COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/tools/check_qml_syntax"
|
||||
)
|
||||
endif ()
|
||||
endif()
|
||||
|
||||
execute_process(COMMAND ${CMAKE_COMMAND} -E copy
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/tools/private/pre-commit"
|
||||
|
|
@ -337,6 +336,7 @@ find_package(Qt5 5.9 COMPONENTS ${QT5_PACKAGES} REQUIRED)
|
|||
find_package(Qt5 5.9 COMPONENTS ${QT5_PACKAGES_OPTIONAL} QUIET)
|
||||
|
||||
if (CMAKE_INSTALL_RPATH)
|
||||
#Retrieve lib path from a know QT executable
|
||||
get_target_property(LUPDATE_PATH Qt5::lupdate LOCATION)
|
||||
get_filename_component(LUPDATE_PATH "${LUPDATE_PATH}" DIRECTORY)
|
||||
get_filename_component(QT_PATH "${LUPDATE_PATH}/../lib" ABSOLUTE)
|
||||
|
|
@ -345,15 +345,18 @@ endif ()
|
|||
|
||||
# Add languages support.
|
||||
add_subdirectory(${LANGUAGES_DIRECTORY})
|
||||
list(APPEND QRC_RESOURCES "${CMAKE_CURRENT_BINARY_DIR}/${LANGUAGES_DIRECTORY}/${I18N_FILENAME}")
|
||||
|
||||
# Add qrc. (images, qml, translations...)
|
||||
qt5_add_resources(RESOURCES ${QRC_RESOURCES})
|
||||
list(APPEND SOURCES "${CMAKE_CURRENT_BINARY_DIR}/${LANGUAGES_DIRECTORY}/${I18N_FILENAME}")
|
||||
|
||||
# Build.
|
||||
add_library(${APP_LIBRARY} OBJECT ${SOURCES} ${HEADERS} ${RESOURCES} ${QML_SOURCES})
|
||||
#add_library(${APP_LIBRARY} OBJECT ${SOURCES} ${HEADERS} ${RESOURCES} ${QML_SOURCES})
|
||||
add_library(${APP_LIBRARY} OBJECT ${SOURCES} ${HEADERS} ${QML_SOURCES} ${QRC_RESOURCES})
|
||||
set_property(TARGET ${APP_LIBRARY} PROPERTY POSITION_INDEPENDENT_CODE ON)
|
||||
|
||||
#Turn on automatic resources compilation by cmake
|
||||
#Instead of excplicitely calling qt5_add_resources
|
||||
set_property(TARGET ${APP_LIBRARY} PROPERTY AUTORCC ON)
|
||||
|
||||
bc_git_version(${TARGET_NAME} ${PROJECT_VERSION})
|
||||
add_dependencies(${APP_LIBRARY} ${TARGET_NAME}-git-version)
|
||||
add_dependencies(${APP_LIBRARY} update_translations)
|
||||
|
|
|
|||
|
|
@ -21,37 +21,66 @@ foreach (lang ${LANGUAGES})
|
|||
# This path is used in `app.cpp`.
|
||||
set(I18N_CONTENT "${I18N_CONTENT} <file alias=\"languages/${lang}\">${lang}.qm</file>\n")
|
||||
|
||||
#Clean existing generated file
|
||||
file(REMOVE "${QM_FILES_OUTPUT_DIR}/${lang}.qm")
|
||||
|
||||
if (${CMAKE_VERSION} VERSION_GREATER "3.12" OR ${CMAKE_VERSION} VERSION_EQUAL "3.12")
|
||||
#Force re-interpretation of ts files. Touch command available only from 3.12 onwards
|
||||
file(TOUCH "${CMAKE_CURRENT_SOURCE_DIR}/${lang}.ts")
|
||||
endif()
|
||||
|
||||
list(APPEND TS_FILES "${CMAKE_CURRENT_SOURCE_DIR}/${lang}.ts")
|
||||
list(APPEND TARGET_TS_FILES "${CMAKE_CURRENT_BINARY_DIR}/${lang}.ts")
|
||||
list(APPEND QM_FILES "${CMAKE_CURRENT_BINARY_DIR}/${lang}.qm")
|
||||
endforeach()
|
||||
|
||||
set(I18N_CONTENT "${I18N_CONTENT} </qresource>\n</RCC>\n")
|
||||
|
||||
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/${I18N_FILENAME}" "${I18N_CONTENT}")
|
||||
|
||||
# Workaround: Create empty files for some cmake versions. Otherwise, the qm rules can't be used.
|
||||
foreach (qm ${QM_FILES})
|
||||
if (NOT EXISTS "${qm}")
|
||||
file(GENERATE OUTPUT "${qm}" CONTENT "")
|
||||
endif()
|
||||
endforeach()
|
||||
#Files or directories to inspect for translations references
|
||||
set(TRANSLATION_SOURCES)
|
||||
list(APPEND TRANSLATION_SOURCES "${PROJECT_SOURCE_DIR}/src")
|
||||
list(APPEND TRANSLATION_SOURCES "${PROJECT_SOURCE_DIR}/ui")
|
||||
|
||||
#qt5 macro: creates or updates ts files from translation routines from all sources files (h,cpp,qml)
|
||||
#Then creates `qm` files from `ts` files which are referenced by the i18n qrc files
|
||||
qt5_create_translation(QM_FILES ${TS_FILES} ${SOURCES} ${HEADERS} ${QML_SOURCES} OPTIONS -no-obsolete)
|
||||
if (WIN32)
|
||||
foreach (lang ${LANGUAGES})
|
||||
file(READ "${CMAKE_CURRENT_SOURCE_DIR}/${lang}.ts" content)
|
||||
set(cleanedContent)
|
||||
string(REPLACE "\r" "" cleanedContent "${content}")
|
||||
file(WRITE "${CMAKE_CURRENT_SOURCE_DIR}/${lang}.ts" "${cleanedContent}")
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
# Update translations.
|
||||
set(LUPDATE_OPTIONS "-no-obsolete")
|
||||
set(LRELEASE_OPTIONS "")
|
||||
|
||||
#Clean existing generated file to force re-creation
|
||||
file(REMOVE ${QM_FILES})
|
||||
file(REMOVE ${TARGET_TS_FILES})
|
||||
|
||||
add_custom_command(OUTPUT ${TARGET_TS_FILES}
|
||||
COMMAND ${Qt5_LUPDATE_EXECUTABLE}
|
||||
ARGS ${LUPDATE_OPTIONS} ${TRANSLATION_SOURCES} -ts ${TS_FILES}
|
||||
COMMAND ${CMAKE_COMMAND} -E copy ${TS_FILES} ${CMAKE_CURRENT_BINARY_DIR}
|
||||
VERBATIM
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
COMMENT "Updating translation source files (ts)..."
|
||||
)
|
||||
|
||||
add_custom_command(OUTPUT ${QM_FILES}
|
||||
COMMAND ${Qt5_LRELEASE_EXECUTABLE}
|
||||
ARGS ${TARGET_TS_FILES} ${LRELEASE_OPTIONS}
|
||||
DEPENDS ${TARGET_TS_FILES}
|
||||
BYPRODUCTS ${QM_FILES}
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
||||
VERBATIM
|
||||
COMMENT "Creating compiled translation files (qm)..."
|
||||
)
|
||||
|
||||
#The dependency on custom_command Output is important
|
||||
add_custom_target(update_translations
|
||||
COMMAND ${CMAKE_COMMAND} "-DLANGUAGES=\"${LANGUAGES}\"" -P "${CMAKE_CURRENT_SOURCE_DIR}/clean_translations.cmake"
|
||||
DEPENDS ${QM_FILES}
|
||||
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
|
||||
)
|
||||
|
||||
# Remove `*.qm` when `clean` is called.
|
||||
set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${QM_FILES}")
|
||||
|
||||
# Workaround: Create empty files for some cmake versions. Otherwise, the qm rules can't be used.
|
||||
# foreach (qm ${QM_FILES})
|
||||
# if (NOT EXISTS "${qm}")
|
||||
# file(GENERATE OUTPUT "${qm}" CONTENT "")
|
||||
# endif()
|
||||
# endforeach()
|
||||
|
|
|
|||
|
|
@ -1,12 +0,0 @@
|
|||
# ==============================================================================
|
||||
# assets/languages/clean_translations.cmake
|
||||
# ==============================================================================
|
||||
|
||||
if (WIN32)
|
||||
foreach (lang ${LANGUAGES})
|
||||
file(READ "${lang}.ts" content)
|
||||
set(cleanedContent)
|
||||
string(REPLACE "\r" "" cleanedContent "${content}")
|
||||
file(WRITE "${lang}.ts" "${cleanedContent}")
|
||||
endforeach ()
|
||||
endif ()
|
||||
Loading…
Add table
Reference in a new issue