diff --git a/.gitignore b/.gitignore index 069d1f6bab..fadeba16a3 100644 --- a/.gitignore +++ b/.gitignore @@ -47,3 +47,6 @@ Jamulus.xcodeproj jamulus_plugin_import.cpp .github_release_changelog.md /debian/ +src/res/qmake_qmake_qm_files.qrc +src/res/qrc_qmake_qmake_qm_files.cpp +src/res/translation/*.qm diff --git a/Jamulus.pro b/Jamulus.pro index 0b2fb55cb5..75d514e2de 100644 --- a/Jamulus.pro +++ b/Jamulus.pro @@ -1,5 +1,9 @@ VERSION = 3.9.1dev +lessThan(QT_MAJOR_VERSION, 5) { + error(Jamulus requires at least Qt5) +} + # use target name which does not use a capital letter at the beginning contains(CONFIG, "noupcasename") { message(The target name is jamulus instead of Jamulus.) @@ -22,7 +26,7 @@ contains(VERSION, .*dev.*) { CONFIG += qt \ thread \ - lrelease + lrelease embed_translations QT += network \ xml \ @@ -707,19 +711,6 @@ DISTFILES += ChangeLog \ src/res/io.jamulus.jamulus.png \ src/res/io.jamulus.jamulus.svg \ src/res/io.jamulus.jamulusserver.svg \ - src/translation/translation_de_DE.qm \ - src/translation/translation_fr_FR.qm \ - src/translation/translation_ko_KR.qm \ - src/translation/translation_pt_PT.qm \ - src/translation/translation_pt_BR.qm \ - src/translation/translation_es_ES.qm \ - src/translation/translation_nb_NO.qm \ - src/translation/translation_nl_NL.qm \ - src/translation/translation_pl_PL.qm \ - src/translation/translation_it_IT.qm \ - src/translation/translation_sv_SE.qm \ - src/translation/translation_sk_SK.qm \ - src/translation/translation_zh_CN.qm \ src/res/CLEDBlack.png \ src/res/CLEDBlackSmall.png \ src/res/CLEDDisabledSmall.png \ @@ -1177,3 +1168,47 @@ CLANG_FORMAT_SOURCES = $$find(CLANG_FORMAT_SOURCES, ^\(android|ios|mac|linux|src CLANG_FORMAT_SOURCES ~= s!^\(libs/.*/|src/res/qrc_resources\.cpp\)\S*$!!g clang_format.commands = 'clang-format -i $$CLANG_FORMAT_SOURCES' QMAKE_EXTRA_TARGETS += clang_format + +equals(QT_MAJOR_VERSION, 5) { + lessThan(QT_MINOR_VERSION, 12) { + message(Using extra lrelease rules for old Qt5 *** IGNORE the RCC errors below ***) + + qtPrepareTool(QMAKE_LRELEASE, lrelease) + + isEmpty(LRELEASE_DIR): LRELEASE_DIR = .qm + isEmpty(QM_FILES_RESOURCE_PREFIX): QM_FILES_RESOURCE_PREFIX = i18n + + lrelease.name = lrelease + lrelease.input = TRANSLATIONS EXTRA_TRANSLATIONS + lrelease.output = $$LRELEASE_DIR/${QMAKE_FILE_IN_BASE}.qm + lrelease.commands = $$QMAKE_LRELEASE ${QMAKE_FILE_IN} $$QMAKE_LRELEASE_FLAGS -qm ${QMAKE_FILE_OUT} + silent: lrelease.commands = @echo lrelease ${QMAKE_FILE_IN} && $$lrelease.commands + lrelease.CONFIG = no_link + QMAKE_EXTRA_COMPILERS += lrelease + + all_translations = $$TRANSLATIONS $$EXTRA_TRANSLATIONS + for (translation, all_translations) { + # mirrors $$LRELEASE_DIR/${QMAKE_FILE_IN_BASE}.qm above + translation = $$basename(translation) + QM_FILES += $$OUT_PWD/$$LRELEASE_DIR/$$replace(translation, \\..*$, .qm) + } + embed_translations { + qmake_qm_files.files = $$QM_FILES + qmake_qm_files.base = $$OUT_PWD/$$LRELEASE_DIR + qmake_qm_files.prefix = $$QM_FILES_RESOURCE_PREFIX + RESOURCES += qmake_qm_files + + # This is a hack because old rcc does not output dependencies that do not yet exist. + # This adds the QM files as explicit dependencies of all resource files, but that + # does not matter - it still ensures the qm files get built on the fly. + rcc.depends += $$QM_FILES + } else { + !isEmpty(QM_FILES_INSTALL_PATH) { + qm_files.files = $$QM_FILES + qm_files.path = $$QM_FILES_INSTALL_PATH + INSTALLS += qm_files + } + lrelease.CONFIG += target_predeps no_clean + } + } +} diff --git a/src/resources.qrc b/src/resources.qrc index 279ddde6fe..502a459b64 100644 --- a/src/resources.qrc +++ b/src/resources.qrc @@ -1,44 +1,4 @@ - - translation/translation_de_DE.qm - - - translation/translation_fr_FR.qm - - - translation/translation_pt_PT.qm - - - translation/translation_pt_BR.qm - - - translation/translation_es_ES.qm - - - translation/translation_nb_NO.qm - - - translation/translation_nl_NL.qm - - - translation/translation_it_IT.qm - - - translation/translation_pl_PL.qm - - - translation/translation_sk_SK.qm - - - translation/translation_sv_SE.qm - - - translation/translation_zh_CN.qm - - - translation/translation_ko_KR.qm - - res/CLEDDisabled.png res/CLEDGrey.png diff --git a/src/util.cpp b/src/util.cpp index 421706c43f..21032aa77a 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -1583,7 +1583,7 @@ QString CLocale::GetCountryFlagIconsResourceReference ( const QLocale::Country e QMap CLocale::GetAvailableTranslations() { QMap TranslMap; - QDirIterator DirIter ( ":/translations" ); + QDirIterator DirIter ( ":/i18n" ); // add english language (default which is in the actual source code) TranslMap["en"] = ""; // empty file name means that the translation load fails and we get the default english language @@ -1593,8 +1593,9 @@ QMap CLocale::GetAvailableTranslations() // get alias of translation file const QString strCurFileName = DirIter.next(); - // extract only language code (must be at the end, separated with a "_") - const QString strLoc = strCurFileName.right ( strCurFileName.length() - strCurFileName.indexOf ( "_" ) - 1 ); + // extract only language code xx_XX from translation_xx_XX.qm + const int lang = strCurFileName.indexOf ( "_" ) + 1; + const QString strLoc = strCurFileName.mid ( lang, strCurFileName.indexOf ( "." ) - lang ); TranslMap[strLoc] = strCurFileName; }