--- mainwindow.cc.orig 2021-03-27 08:55:40.000000000 -0700 +++ mainwindow.cc 2021-03-27 08:51:38.000000000 -0700 @@ -26,11 +26,14 @@ #include // for QEvent (& QEvent::LanguageChange, QEvent::LocaleChange) #include // for QFile #include // for QFileInfo +#include // for QLibraryInfo, QLibraryInfo::TranslationsPath #include // for QLocale #include // for QMimeData #include // for QProcess, QProcess::NotRunning #include // for QRegExp #include // for QSettings +#include // for QString +#include // for QStringList #include // for QTemporaryFile #include // for QTime #include // for QUrl @@ -219,9 +222,6 @@ ui_.outputWindow->setReadOnly(true); - langPath_ = QApplication::applicationDirPath(); - langPath_.append("/translations/"); - // Start up in the current system language. loadLanguage(QLocale::system().name()); loadFormats(); @@ -311,9 +311,25 @@ // remove the old translator qApp->removeTranslator(&translator); - // load the new translator - if (translator.load(filename, langPath_)) { - qApp->installTranslator(&translator); + // Set a list of locations to search for the translation file. + // 1. In the file system in the translations directory relative to the + // location of the executable. + // 2. In the Qt resource system under the translations path. This is useful + // if the resource was compiled into the executable. + // 3. In the translations path for Qt. This is useful to find translations + // included with Qt. + const QStringList directories = { + QApplication::applicationDirPath() + "/translations", + ":/translations", + QLibraryInfo::location(QLibraryInfo::TranslationsPath) + }; + + // Load the new translator. + for (const auto& directory : directories) { + if (translator.load(filename, directory)) { + qApp->installTranslator(&translator); + break; + } } } --- mainwindow.h.orig 2021-03-27 08:55:47.000000000 -0700 +++ mainwindow.h 2021-03-27 08:51:38.000000000 -0700 @@ -70,7 +70,6 @@ QTranslator translatorCore_; // translation for the core application. QTranslator translatorQt_; // translations for Qt. QString currLang_; // currently loaded language. - QString langPath_; // Absolute path of language files. private: void loadFormats();