Allow built-in translations via qtutilities
Allow bundling translations as resources by setting `BUILTIN_TRANSLATIONS`. This is useful to create self-contained executables. The code for this is already in qtutilities so we basically just need to look within the resource root `:/` for translations as well and tweak the build script a little. With this change it is still possible to load translations separately from the usual locations as it is only effective if `BUILTIN_TRANSLATIONS` is set to a truthy value.
This commit is contained in:
parent
0d8ebc6743
commit
54402c2483
|
@ -163,7 +163,7 @@ endif (USE_FTGL)
|
|||
if (NO_LANGS)
|
||||
add_compile_options("-DNO_LANGS")
|
||||
else ()
|
||||
add_subdirectory(../translations ../build/translations)
|
||||
add_subdirectory(../translations ../build/translations-subdir)
|
||||
endif ()
|
||||
|
||||
# find Qt libraries
|
||||
|
|
|
@ -319,6 +319,9 @@ QString Util::dataDir(const QString &subDir) {
|
|||
if (const auto nextToBin = QString(appDirPath % QChar('/') % subDir); QFile::exists(nextToBin)) {
|
||||
return nextToBin;
|
||||
}
|
||||
if (const auto builtIn = QStringLiteral(":/") + subDir; QFile::exists(builtIn)) {
|
||||
return builtIn;
|
||||
}
|
||||
#ifdef Q_OS_DARWIN
|
||||
return appDirPath % QStringLiteral("/../Resources/") % subDir;
|
||||
#else
|
||||
|
|
|
@ -25,15 +25,21 @@ endif ()
|
|||
get_filename_component(full_path_blank_ts ${CMAKE_CURRENT_SOURCE_DIR}/pianobooster_blank.ts ABSOLUTE)
|
||||
list(REMOVE_ITEM TRANSLATIONS_FILES ${full_path_blank_ts})
|
||||
|
||||
# set TS_FILES and EXTERNAL_QM_FILESj to let qtutilities handle translation processing
|
||||
foreach (TS_FILE ${TRANSLATIONS_FILES})
|
||||
list(APPEND TS_FILES "../translations/${TS_FILE}")
|
||||
endforeach ()
|
||||
set(TS_FILES "${TS_FILES}" PARENT_SCOPE)
|
||||
set(EXTERNAL_QM_FILES "${CMAKE_CURRENT_BINARY_DIR}/../langs.json" PARENT_SCOPE)
|
||||
|
||||
if ((UNIX OR MINGW) AND NOT APPLE)
|
||||
install(FILES langs.json DESTINATION ${DATA_DIR}/translations)
|
||||
elseif (WIN32)
|
||||
install(FILES langs.json DESTINATION .)
|
||||
# allow to built-in translations (via qtutilities); otherwise install langs.json normally
|
||||
option(BUILTIN_TRANSLATIONS "enables/disables built-in translations" OFF)
|
||||
if (NOT BUILTIN_TRANSLATIONS)
|
||||
if ((UNIX OR MINGW) AND NOT APPLE)
|
||||
install(FILES langs.json DESTINATION ${DATA_DIR}/translations)
|
||||
elseif (WIN32)
|
||||
install(FILES langs.json DESTINATION .)
|
||||
endif ()
|
||||
endif ()
|
||||
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/langs.json ${CMAKE_CURRENT_BINARY_DIR}/ COPYONLY)
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/langs.json ${CMAKE_CURRENT_BINARY_DIR}/.. COPYONLY)
|
||||
|
|
Loading…
Reference in New Issue