Make Qt base translation embedding disableable
This commit is contained in:
@@ -455,46 +455,52 @@ if (UNIX AND NOT APPLE AND NOT HAIKU)
|
|||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Get the Qt translations directory
|
option(EMBED_QTBASE_TRANSLATIONS "Embed the base Qt translations into the executable" ON)
|
||||||
get_target_property(QT_QMAKE_EXECUTABLE Qt${QT_MAJOR}::qmake IMPORTED_LOCATION)
|
|
||||||
execute_process(COMMAND ${QT_QMAKE_EXECUTABLE} -query QT_INSTALL_TRANSLATIONS OUTPUT_VARIABLE QT_TRANSLATIONS_DIR OUTPUT_STRIP_TRAILING_WHITESPACE)
|
if (EMBED_QTBASE_TRANSLATIONS)
|
||||||
|
# Get the Qt translations directory
|
||||||
|
get_target_property(QT_QMAKE_EXECUTABLE Qt${QT_MAJOR}::qmake IMPORTED_LOCATION)
|
||||||
|
execute_process(COMMAND ${QT_QMAKE_EXECUTABLE} -query QT_INSTALL_TRANSLATIONS OUTPUT_VARIABLE QT_TRANSLATIONS_DIR OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||||
|
endif()
|
||||||
|
|
||||||
set(QM_FILES)
|
set(QM_FILES)
|
||||||
file(GLOB po_files "${CMAKE_CURRENT_SOURCE_DIR}/languages/*.po")
|
file(GLOB po_files "${CMAKE_CURRENT_SOURCE_DIR}/languages/*.po")
|
||||||
foreach(po_file ${po_files})
|
foreach(po_file ${po_files})
|
||||||
get_filename_component(PO_FILE_NAME ${po_file} NAME_WE)
|
get_filename_component(PO_FILE_NAME ${po_file} NAME_WE)
|
||||||
|
|
||||||
# Get the language and country
|
if (EMBED_QTBASE_TRANSLATIONS)
|
||||||
string(REGEX MATCH "^[a-z]+" PO_LANGUAGE ${PO_FILE_NAME})
|
# Get the language and country
|
||||||
string(REGEX MATCH "[A-Z]+$" PO_COUNTRY ${PO_FILE_NAME})
|
string(REGEX MATCH "^[a-z]+" PO_LANGUAGE ${PO_FILE_NAME})
|
||||||
|
string(REGEX MATCH "[A-Z]+$" PO_COUNTRY ${PO_FILE_NAME})
|
||||||
|
|
||||||
# Find the base Qt translation for the language and country
|
# Find the base Qt translation for the language and country
|
||||||
set(qt_translation_file_dest "qt_${PO_LANGUAGE}_${PO_COUNTRY}.qm")
|
set(qt_translation_file_dest "qt_${PO_LANGUAGE}_${PO_COUNTRY}.qm")
|
||||||
if (EXISTS "${QT_TRANSLATIONS_DIR}/qtbase_${PO_LANGUAGE}_${PO_COUNTRY}.qm")
|
if (EXISTS "${QT_TRANSLATIONS_DIR}/qtbase_${PO_LANGUAGE}_${PO_COUNTRY}.qm")
|
||||||
set(qt_translation_file "qtbase_${PO_LANGUAGE}_${PO_COUNTRY}.qm")
|
set(qt_translation_file "qtbase_${PO_LANGUAGE}_${PO_COUNTRY}.qm")
|
||||||
# Fall back to just the language if country isn't found
|
# Fall back to just the language if country isn't found
|
||||||
elseif (EXISTS "${QT_TRANSLATIONS_DIR}/qtbase_${PO_LANGUAGE}.qm")
|
elseif (EXISTS "${QT_TRANSLATIONS_DIR}/qtbase_${PO_LANGUAGE}.qm")
|
||||||
set(qt_translation_file "qtbase_${PO_LANGUAGE}.qm")
|
set(qt_translation_file "qtbase_${PO_LANGUAGE}.qm")
|
||||||
# If the translation is still not found, try the legacy Qt one
|
# If the translation is still not found, try the legacy Qt one
|
||||||
elseif (EXISTS "${QT_TRANSLATIONS_DIR}/qt_${PO_LANGUAGE}_${PO_COUNTRY}.qm")
|
elseif (EXISTS "${QT_TRANSLATIONS_DIR}/qt_${PO_LANGUAGE}_${PO_COUNTRY}.qm")
|
||||||
set(qt_translation_file "qt_${PO_LANGUAGE}_${PO_COUNTRY}.qm")
|
set(qt_translation_file "qt_${PO_LANGUAGE}_${PO_COUNTRY}.qm")
|
||||||
# Fall back to just the language again
|
# Fall back to just the language again
|
||||||
elseif (EXISTS "${QT_TRANSLATIONS_DIR}/qt_${PO_LANGUAGE}.qm")
|
elseif (EXISTS "${QT_TRANSLATIONS_DIR}/qt_${PO_LANGUAGE}.qm")
|
||||||
set(qt_translation_file "qt_${PO_LANGUAGE}.qm")
|
set(qt_translation_file "qt_${PO_LANGUAGE}.qm")
|
||||||
else()
|
else()
|
||||||
unset(qt_translation_file)
|
unset(qt_translation_file)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Copy the translation file to the build directory
|
# Copy the translation file to the build directory
|
||||||
if (qt_translation_file)
|
if (qt_translation_file)
|
||||||
file(COPY "${QT_TRANSLATIONS_DIR}/${qt_translation_file}" DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
|
file(COPY "${QT_TRANSLATIONS_DIR}/${qt_translation_file}" DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
|
||||||
if (NOT (qt_translation_file STREQUAL qt_translation_file_dest))
|
if (NOT (qt_translation_file STREQUAL qt_translation_file_dest))
|
||||||
# Rename the file for consistency
|
# Rename the file for consistency
|
||||||
file(RENAME "${CMAKE_CURRENT_BINARY_DIR}/${qt_translation_file}" "${CMAKE_CURRENT_BINARY_DIR}/${qt_translation_file_dest}")
|
file(RENAME "${CMAKE_CURRENT_BINARY_DIR}/${qt_translation_file}" "${CMAKE_CURRENT_BINARY_DIR}/${qt_translation_file_dest}")
|
||||||
|
endif()
|
||||||
|
# Add the file to the translations list
|
||||||
|
string(APPEND QT_TRANSLATIONS_LIST " <file>${qt_translation_file_dest}</file>\n")
|
||||||
|
list(APPEND QM_FILES "${CMAKE_CURRENT_BINARY_DIR}/${qt_translation_file_dest}")
|
||||||
endif()
|
endif()
|
||||||
# Add the file to the translations list
|
|
||||||
string(APPEND QT_TRANSLATIONS_LIST " <file>${qt_translation_file_dest}</file>\n")
|
|
||||||
list(APPEND QM_FILES "${CMAKE_CURRENT_BINARY_DIR}/${qt_translation_file_dest}")
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/86box_${PO_FILE_NAME}.qm"
|
add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/86box_${PO_FILE_NAME}.qm"
|
||||||
|
|||||||
Reference in New Issue
Block a user