feat: new TRANSLATION_RESOURCE_EMBEDDING build-time option
This commit is contained in:
parent
57354fc135
commit
2de9ff810d
2
.github/workflows/macos.yml
vendored
2
.github/workflows/macos.yml
vendored
@ -16,7 +16,7 @@ jobs:
|
|||||||
modules: 'qtimageformats'
|
modules: 'qtimageformats'
|
||||||
- name: Run a qt project
|
- name: Run a qt project
|
||||||
run: |
|
run: |
|
||||||
cmake . -Bbuild
|
cmake . -Bbuild -DTRANSLATION_RESOURCE_EMBEDDING=ON
|
||||||
cmake --build build
|
cmake --build build
|
||||||
- name: Deploy
|
- name: Deploy
|
||||||
run: |
|
run: |
|
||||||
|
@ -11,6 +11,7 @@ include (FeatureSummary)
|
|||||||
|
|
||||||
option (EXIV2_METADATA_SUPPORT "Better image metadata support via libexiv2" ON)
|
option (EXIV2_METADATA_SUPPORT "Better image metadata support via libexiv2" ON)
|
||||||
option (PREFER_QT_5 "Prefer to use Qt 5" OFF)
|
option (PREFER_QT_5 "Prefer to use Qt 5" OFF)
|
||||||
|
option (TRANSLATION_RESOURCE_EMBEDDING "Embedding .qm translation files inside resource" OFF)
|
||||||
|
|
||||||
set (CMAKE_CXX_STANDARD 17)
|
set (CMAKE_CXX_STANDARD 17)
|
||||||
set (CMAKE_CXX_STANDARD_REQUIRED ON)
|
set (CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
@ -115,7 +116,11 @@ add_executable (${EXE_NAME}
|
|||||||
)
|
)
|
||||||
|
|
||||||
if (${QT_VERSION_MAJOR} EQUAL "6")
|
if (${QT_VERSION_MAJOR} EQUAL "6")
|
||||||
|
if (TRANSLATION_RESOURCE_EMBEDDING)
|
||||||
|
qt_add_translations(${EXE_NAME} TS_FILES ${PPIC_TS_FILES})
|
||||||
|
else()
|
||||||
qt_add_translations(${EXE_NAME} TS_FILES ${PPIC_TS_FILES} QM_FILES_OUTPUT_VARIABLE PPIC_QM_FILES)
|
qt_add_translations(${EXE_NAME} TS_FILES ${PPIC_TS_FILES} QM_FILES_OUTPUT_VARIABLE PPIC_QM_FILES)
|
||||||
|
endif()
|
||||||
else()
|
else()
|
||||||
qt_create_translation(PPIC_QM_FILES ${PPIC_CPP_FILES_FOR_I18N} ${PPIC_TS_FILES})
|
qt_create_translation(PPIC_QM_FILES ${PPIC_CPP_FILES_FOR_I18N} ${PPIC_TS_FILES})
|
||||||
endif()
|
endif()
|
||||||
@ -256,19 +261,25 @@ install (
|
|||||||
${INSTALL_TARGETS_DEFAULT_ARGS}
|
${INSTALL_TARGETS_DEFAULT_ARGS}
|
||||||
)
|
)
|
||||||
|
|
||||||
if (WIN32)
|
if (TRANSLATION_RESOURCE_EMBEDDING)
|
||||||
|
target_compile_definitions(${EXE_NAME}
|
||||||
|
PRIVATE TRANSLATION_RESOURCE_EMBEDDING
|
||||||
|
)
|
||||||
|
elseif (WIN32)
|
||||||
set (QM_FILE_INSTALL_DIR "${CMAKE_INSTALL_BINDIR}/translations")
|
set (QM_FILE_INSTALL_DIR "${CMAKE_INSTALL_BINDIR}/translations")
|
||||||
else ()
|
else()
|
||||||
set (QM_FILE_INSTALL_DIR "${CMAKE_INSTALL_FULL_DATADIR}/pineapple-pictures/translations")
|
set (QM_FILE_INSTALL_DIR "${CMAKE_INSTALL_FULL_DATADIR}/pineapple-pictures/translations")
|
||||||
target_compile_definitions(${EXE_NAME}
|
target_compile_definitions(${EXE_NAME}
|
||||||
PRIVATE QM_FILE_INSTALL_DIR=${QM_FILE_INSTALL_DIR}
|
PRIVATE QM_FILE_INSTALL_ABSOLUTE_DIR=${QM_FILE_INSTALL_DIR}
|
||||||
)
|
)
|
||||||
endif ()
|
endif()
|
||||||
|
|
||||||
install (
|
if (DEFINED QM_FILE_INSTALL_DIR)
|
||||||
|
install(
|
||||||
FILES ${PPIC_QM_FILES}
|
FILES ${PPIC_QM_FILES}
|
||||||
DESTINATION ${QM_FILE_INSTALL_DIR}
|
DESTINATION ${QM_FILE_INSTALL_DIR}
|
||||||
)
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
feature_summary(WHAT ALL INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES)
|
feature_summary(WHAT ALL INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES)
|
||||||
|
|
||||||
|
14
app/main.cpp
14
app/main.cpp
@ -13,11 +13,6 @@
|
|||||||
#include <QTranslator>
|
#include <QTranslator>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
|
|
||||||
// QM_FILE_INSTALL_DIR should be defined from the CMakeLists file.
|
|
||||||
#ifndef QM_FILE_INSTALL_DIR
|
|
||||||
#define QM_FILE_INSTALL_DIR ":/i18n/"
|
|
||||||
#endif // QM_FILE_INSTALL_DIR
|
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
QCoreApplication::setApplicationName("Pineapple Pictures");
|
QCoreApplication::setApplicationName("Pineapple Pictures");
|
||||||
@ -30,11 +25,12 @@ int main(int argc, char *argv[])
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
QTranslator translator;
|
QTranslator translator;
|
||||||
QString qmDir;
|
#if defined(TRANSLATION_RESOURCE_EMBEDDING)
|
||||||
#ifdef _WIN32
|
const QString qmDir = QLatin1String(":/i18n/");
|
||||||
qmDir = QDir(QCoreApplication::applicationDirPath()).absoluteFilePath("translations");
|
#elif defined(QM_FILE_INSTALL_ABSOLUTE_DIR)
|
||||||
|
const QString qmDir = QT_STRINGIFY(QM_FILE_INSTALL_ABSOLUTE_DIR);
|
||||||
#else
|
#else
|
||||||
qmDir = QT_STRINGIFY(QM_FILE_INSTALL_DIR);
|
const QString qmDir = QDir(QCoreApplication::applicationDirPath()).absoluteFilePath("translations");
|
||||||
#endif
|
#endif
|
||||||
if (translator.load(QLocale(), QLatin1String("PineapplePictures"), QLatin1String("_"), qmDir)) {
|
if (translator.load(QLocale(), QLatin1String("PineapplePictures"), QLatin1String("_"), qmDir)) {
|
||||||
QCoreApplication::installTranslator(&translator);
|
QCoreApplication::installTranslator(&translator);
|
||||||
|
Loading…
Reference in New Issue
Block a user