Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build: Generate qm files and embedded resource during build #2393

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
63 changes: 49 additions & 14 deletions Jamulus.pro
Original file line number Diff line number Diff line change
@@ -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.)
Expand All @@ -22,7 +26,7 @@ contains(VERSION, .*dev.*) {

CONFIG += qt \
thread \
lrelease
lrelease embed_translations

QT += network \
xml \
Expand Down Expand Up @@ -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 \
Expand Down Expand Up @@ -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
}
}
}
40 changes: 0 additions & 40 deletions src/resources.qrc
Original file line number Diff line number Diff line change
@@ -1,44 +1,4 @@
<RCC>
<qresource prefix="/translations">
<file alias="translation_de">translation/translation_de_DE.qm</file>
</qresource>
<qresource prefix="/translations">
<file alias="translation_fr">translation/translation_fr_FR.qm</file>
</qresource>
<qresource prefix="/translations">
<file alias="translation_pt_PT">translation/translation_pt_PT.qm</file>
</qresource>
<qresource prefix="/translations">
<file alias="translation_pt">translation/translation_pt_BR.qm</file>
</qresource>
<qresource prefix="/translations">
<file alias="translation_es">translation/translation_es_ES.qm</file>
</qresource>
<qresource prefix="/translations">
<file alias="translation_nb_NO">translation/translation_nb_NO.qm</file>
</qresource>
<qresource prefix="/translations">
<file alias="translation_nl">translation/translation_nl_NL.qm</file>
</qresource>
<qresource prefix="/translations">
<file alias="translation_it">translation/translation_it_IT.qm</file>
</qresource>
<qresource prefix="/translations">
<file alias="translation_pl">translation/translation_pl_PL.qm</file>
</qresource>
<qresource prefix="/translations">
<file alias="translation_sk">translation/translation_sk_SK.qm</file>
</qresource>
<qresource prefix="/translations">
<file alias="translation_sv">translation/translation_sv_SE.qm</file>
</qresource>
<qresource prefix="/translations">
<file alias="translation_zh_CN">translation/translation_zh_CN.qm</file>
</qresource>
<qresource prefix="/translations">
<file alias="translation_ko_KR">translation/translation_ko_KR.qm</file>
</qresource>

<qresource prefix="/png/LEDs">
<file>res/CLEDDisabled.png</file>
<file>res/CLEDGrey.png</file>
Expand Down
7 changes: 4 additions & 3 deletions src/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1583,7 +1583,7 @@ QString CLocale::GetCountryFlagIconsResourceReference ( const QLocale::Country e
QMap<QString, QString> CLocale::GetAvailableTranslations()
{
QMap<QString, QString> 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
Expand All @@ -1593,8 +1593,9 @@ QMap<QString, QString> 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;
}
Expand Down