Skip to content

Commit

Permalink
Merge pull request #3288 from softins/embed-translations
Browse files Browse the repository at this point in the history
Build: Generate qm files and embedded resource during build
  • Loading branch information
ann0see authored Jun 22, 2024
2 parents 53d3f09 + 97306e7 commit 34e4d6e
Show file tree
Hide file tree
Showing 18 changed files with 26 additions and 63 deletions.
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Jamulus
Jamulus.ini
Makefile
Makefile.*
*.pro.user*
**.cppe
**.he
Expand All @@ -17,7 +18,11 @@ Makefile
moc_*.cpp
ui_*.h
moc_predefs.h
src/res/qrc_resources.cpp
.qm/
*.qm
qmake_qmake_qm_files.qrc
qrc_qmake_qmake_qm_files.cpp
qrc_resources.cpp
libs/ASIOSDK2
windows/VC_redist.x64.exe
windows/vc_redist.x86.exe
Expand Down
30 changes: 12 additions & 18 deletions Jamulus.pro
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
VERSION = 3.10.0dev

# Using lrelease and embed_translations only works for Qt 5.12 or later.
# See https://github.com/jamulussoftware/jamulus/pull/3288 for these changes.
lessThan(QT_MAJOR_VERSION, 5) | equals(QT_MAJOR_VERSION, 5) : lessThan(QT_MINOR_VERSION, 12) {
error(Jamulus requires at least Qt5.12. See https://github.com/jamulussoftware/jamulus/pull/3288)
}

# 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 +28,8 @@ contains(VERSION, .*dev.*) {

CONFIG += qt \
thread \
lrelease
lrelease \
embed_translations

QT += network \
xml \
Expand All @@ -42,9 +49,8 @@ contains(CONFIG, "headless") {
QT += multimedia
}

# Hint: When adding new translations, make sure to update
# DISTFILES (above) and src/resources.qrc as well.
LRELEASE_DIR = src/translation
# Do not set LRELEASE_DIR explicitly when using embed_translations.
# It doesn't work with multiple targets or architectures.
TRANSLATIONS = src/translation/translation_de_DE.ts \
src/translation/translation_fr_FR.ts \
src/translation/translation_ko_KR.ts \
Expand Down Expand Up @@ -357,7 +363,8 @@ win32 {
}
}

RCC_DIR = src/res
# Do not set RCC_DIR explicitly when using embed_translations.
# It doesn't work with multiple targets or architectures.
RESOURCES += src/resources.qrc

FORMS_GUI = src/aboutdlgbase.ui \
Expand Down Expand Up @@ -702,19 +709,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
1 change: 0 additions & 1 deletion linux/debian/rules
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ override_dh_auto_configure:
mkdir -p build-nox && cd build-nox && $(QMAKE) "CONFIG+=headless serveronly" TARGET=jamulus-headless PREFIX=/usr ../Jamulus.pro

override_dh_auto_build:
cd src/translation && lrelease *.ts
cd build-gui && make -j "$$(nproc)"
cd build-nox && make -j "$$(nproc)"

Expand Down
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
Binary file removed src/translation/translation_de_DE.qm
Binary file not shown.
Binary file removed src/translation/translation_es_ES.qm
Binary file not shown.
Binary file removed src/translation/translation_fr_FR.qm
Binary file not shown.
Binary file removed src/translation/translation_it_IT.qm
Binary file not shown.
Binary file removed src/translation/translation_ko_KR.qm
Binary file not shown.
Binary file removed src/translation/translation_nb_NO.qm
Binary file not shown.
Binary file removed src/translation/translation_nl_NL.qm
Binary file not shown.
Binary file removed src/translation/translation_pl_PL.qm
Binary file not shown.
Binary file removed src/translation/translation_pt_BR.qm
Binary file not shown.
Binary file removed src/translation/translation_pt_PT.qm
Binary file not shown.
Binary file removed src/translation/translation_sk_SK.qm
Binary file not shown.
Binary file removed src/translation/translation_sv_SE.qm
Binary file not shown.
Binary file removed src/translation/translation_zh_CN.qm
Binary file not shown.
11 changes: 8 additions & 3 deletions src/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1602,7 +1602,11 @@ QString CLocale::GetCountryFlagIconsResourceReference ( const QLocale::Country e
QMap<QString, QString> CLocale::GetAvailableTranslations()
{
QMap<QString, QString> TranslMap;
QDirIterator DirIter ( ":/translations" );

// Since we use "embed_translations" in Jamulus.pro, this resource prefix must
// match the default prefix used by qmake when generating the resource file.
// That prefix is "i18n" (standard abbreviation for internationalisation).
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 @@ -1612,8 +1616,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

0 comments on commit 34e4d6e

Please sign in to comment.