Skip to content

Commit

Permalink
Fix Qt 5 compatibility of our Qt translation use
Browse files Browse the repository at this point in the history
With modularization of Qt 5 some - but not all - of the qt_<locale>.ts files have become
so-called meta catalogues which no longer contain actual translations but refer to other
more specific ts files like qtbase_<locale>.ts . To successfully load a meta catalogue all
of its referenced translations must be available. As we do not want to bundle them all and
we now try to load the old qt_<locale>.ts file first and then fall back to loading
qtbase_<locale>.ts if that failed.

See http://doc.qt.io/qt-5/linguist-programmers.html#deploying-translations for more information

Fixes #1785
  • Loading branch information
hacst committed Aug 20, 2015
1 parent d110e56 commit 4794770
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions src/mumble/main.cpp
Expand Up @@ -315,8 +315,6 @@ int main(int argc, char **argv) {


Themes::apply(); Themes::apply();


QDir::addSearchPath(QLatin1String("translation"), QLatin1String(":/"));

QString qsSystemLocale = QLocale::system().name(); QString qsSystemLocale = QLocale::system().name();


#ifdef Q_OS_MAC #ifdef Q_OS_MAC
Expand All @@ -330,19 +328,32 @@ int main(int argc, char **argv) {
qWarning("Locale is \"%s\" (System: \"%s\")", qPrintable(locale), qPrintable(qsSystemLocale)); qWarning("Locale is \"%s\" (System: \"%s\")", qPrintable(locale), qPrintable(qsSystemLocale));


QTranslator translator; QTranslator translator;
if (translator.load(QLatin1String("translation:mumble_") + locale)) if (translator.load(QLatin1String(":mumble_") + locale))
a.installTranslator(&translator); a.installTranslator(&translator);


QTranslator loctranslator; QTranslator loctranslator;
if (loctranslator.load(QLatin1String("mumble_") + locale, a.applicationDirPath())) if (loctranslator.load(QLatin1String("mumble_") + locale, a.applicationDirPath()))
a.installTranslator(&loctranslator); a.installTranslator(&loctranslator); // Can overwrite strings from bundled mumble translation


// With modularization of Qt 5 some - but not all - of the qt_<locale>.ts files have become
// so-called meta catalogues which no longer contain actual translations but refer to other
// more specific ts files like qtbase_<locale>.ts . To successfully load a meta catalogue all
// of its referenced translations must be available. As we do not want to bundle them all
// we now try to load the old qt_<locale>.ts file first and then fall back to loading
// qtbase_<locale>.ts if that failed.
//
// See http://doc.qt.io/qt-5/linguist-programmers.html#deploying-translations for more information
QTranslator qttranslator; QTranslator qttranslator;
if (qttranslator.load(QLibraryInfo::location(QLibraryInfo::TranslationsPath) + QLatin1String("/qt_") + locale)) if (qttranslator.load(QLatin1String("qt_") + locale, QLibraryInfo::location(QLibraryInfo::TranslationsPath))) { // Try system qt translations
a.installTranslator(&qttranslator); a.installTranslator(&qttranslator);
else if (qttranslator.load(QLatin1String("translation:qt_") + locale)) } else if (qttranslator.load(QLatin1String("qtbase_") + locale, QLibraryInfo::location(QLibraryInfo::TranslationsPath))) {
a.installTranslator(&qttranslator); a.installTranslator(&qttranslator);

} else if (qttranslator.load(QLatin1String(":qt_") + locale)) { // Try bundled translations
a.installTranslator(&qttranslator);
} else if (qttranslator.load(QLatin1String(":qtbase_") + locale)) {
a.installTranslator(&qttranslator);
}

if (g.s.qsRegionalHost.isEmpty()) { if (g.s.qsRegionalHost.isEmpty()) {
g.s.qsRegionalHost = qsSystemLocale; g.s.qsRegionalHost = qsSystemLocale;
g.s.qsRegionalHost = g.s.qsRegionalHost.remove(QRegExp(QLatin1String("^.+_"))).toLower() + QLatin1String(".mumble.info"); g.s.qsRegionalHost = g.s.qsRegionalHost.remove(QRegExp(QLatin1String("^.+_"))).toLower() + QLatin1String(".mumble.info");
Expand Down

0 comments on commit 4794770

Please sign in to comment.