Skip to content

Commit

Permalink
Merge pull request mixxxdj#11134 from daschuer/gh11110
Browse files Browse the repository at this point in the history
Install Qt Translation on MacOS
  • Loading branch information
Swiftb0y committed Jan 17, 2023
2 parents af02d52 + 0a9daa7 commit 5a3e9b8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 24 deletions.
28 changes: 15 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1496,19 +1496,6 @@ if(MSVC)
endif()

if(WIN32)
# qt_de.qm is just one arbitrary file in the directory that needs to be located;
# there is no particular reason to look for this file versus any other one in the directory.
find_file(QT_TRANSLATION_FILE qt_de.qm PATH_SUFFIXES share/qt5/translations)
get_filename_component(QT_TRANSLATIONS ${QT_TRANSLATION_FILE} DIRECTORY)
install(
DIRECTORY "${QT_TRANSLATIONS}"
DESTINATION "${MIXXX_INSTALL_DATADIR}"
# QT 5 translations have been separated into several files, and most of the qt_xx.qm files
# contain just shortcuts to load the qtbase, qtmultimedia etc files.
FILES_MATCHING REGEX
"qt_.+\.qm|qtbase_.*\.qm|qtmultimedia_.*\.qm|qtscript_.*\.qm|qtxmlpatterns_.*\.qm"
)

# Qt 5 loads these ANGLE DLLs at runtime if the graphics driver is blocklisted.
# Qt does not link these and vcpkg does not build them as a dependency of Qt,
# so copy them manually.
Expand Down Expand Up @@ -2185,6 +2172,21 @@ elseif(WIN32)
endif()
endif()

if(APPLE OR WIN32)
# qt_de.qm is just one arbitrary file in the directory that needs to be located;
# there is no particular reason to look for this file versus any other one in the directory.
find_file(QT_TRANSLATION_FILE qt_de.qm PATHS "${Qt5_DIR}/../../../translations" "${Qt5_DIR}/../../qt5/translations" REQUIRED NO_DEFAULT_PATH)
get_filename_component(QT_TRANSLATIONS ${QT_TRANSLATION_FILE} DIRECTORY)
install(
DIRECTORY "${QT_TRANSLATIONS}"
DESTINATION "${MIXXX_INSTALL_DATADIR}"
# QT 5 translations have been separated into several files, and most of the qt_xx.qm files
# contain just shortcuts to load the qtbase, qtmultimedia etc files.
FILES_MATCHING REGEX
"qt_.+\.qm|qtbase_.*\.qm|qtmultimedia_.*\.qm|qtscript_.*\.qm|qtxmlpatterns_.*\.qm"
)
endif()

# QtScriptByteArray
add_library(QtScriptByteArray STATIC EXCLUDE_FROM_ALL
lib/qtscript-bytearray/bytearrayclass.cpp
Expand Down
24 changes: 13 additions & 11 deletions src/util/translations.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,17 @@ class Translations {

// Load Qt translations for this locale from the system translation
// path. This is the lowest precedence QTranslator.
installTranslations(pApp,
bool qtFound = installTranslations(pApp,
locale,
QStringLiteral("qt"),
QLibraryInfo::location(QLibraryInfo::TranslationsPath),
true);
false);

// Load Qt translations for this locale from the Mixxx translations
// folder.
// Depending on the OS, this might not be necessary, so we don't warn
// on failure here.
installTranslations(pApp, locale, QStringLiteral("qt"), translationsPath, false);
if (!qtFound) {
// Alternative, load Qt translations for this locale from the Mixxx translations
// folder.
installTranslations(pApp, locale, QStringLiteral("qt"), translationsPath, true);
}

// Load Mixxx specific translations for this locale from the Mixxx
// translations folder.
Expand All @@ -97,10 +97,12 @@ class Translations {
const bool success = pTranslator->load(
locale, translation, QStringLiteral("_"), translationsPath);
if (!success) {
((warnOnFailure) ? qWarning() : qDebug())
<< "Failed to load" << translation << "translations for locale"
<< locale.name()
<< "from" << translationsPath;
if (warnOnFailure) {
qWarning()
<< "Failed to load" << translation << "translations for locale"
<< locale.name()
<< "from" << translationsPath;
}
delete pTranslator;
return false;
}
Expand Down

0 comments on commit 5a3e9b8

Please sign in to comment.