From 5c92622ad631d3fea5f173e5c0267b9bd1b15b2d Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Sun, 23 Oct 2011 13:37:39 +0200 Subject: [PATCH] Translation lookup logic improvements - use wildcard for TRANSLATIONS in bitcoin-qt.pro to automatically build all translations present in src/qt/locale (thanks @tcatm) - first load translations/.qm, then translations/_.qm, so that territory-specific translations take precedence, but the fallback is on the base language if no territory-specific translation exists. --- bitcoin-qt.pro | 6 ++---- src/qt/bitcoin.cpp | 25 +++++++++++++++++++------ src/qt/bitcoin.qrc | 9 ++++++--- 3 files changed, 27 insertions(+), 13 deletions(-) diff --git a/bitcoin-qt.pro b/bitcoin-qt.pro index 2e4000e52..e9dc6f787 100644 --- a/bitcoin-qt.pro +++ b/bitcoin-qt.pro @@ -175,10 +175,8 @@ FORMS += \ CODECFORTR = UTF-8 # for lrelease/lupdate -TRANSLATIONS = src/qt/locale/bitcoin_de.ts \ - src/qt/locale/bitcoin_es.ts \ - src/qt/locale/bitcoin_nl.ts \ - src/qt/locale/bitcoin_ru.ts +# also add new translations to src/qt/bitcoin.qrc under translations/ +TRANSLATIONS = $$files(src/qt/locale/bitcoin_*.ts) isEmpty(QMAKE_LRELEASE) { win32:QMAKE_LRELEASE = $$[QT_INSTALL_BINS]\lrelease.exe diff --git a/src/qt/bitcoin.cpp b/src/qt/bitcoin.cpp index c8e332419..86ac8a027 100644 --- a/src/qt/bitcoin.cpp +++ b/src/qt/bitcoin.cpp @@ -118,14 +118,27 @@ int main(int argc, char *argv[]) Q_INIT_RESOURCE(bitcoin); QApplication app(argc, argv); - // Load language file for system locale - QString locale = QLocale::system().name(); - QTranslator qtTranslator; - qtTranslator.load(QLibraryInfo::location(QLibraryInfo::TranslationsPath) + "/qt_" + locale); + // Load language files for system locale: + // - First load the translator for the base language, without territory + // - Then load the more specific locale translator + QString lang_territory = QLocale::system().name(); // "en_US" + QString lang = lang_territory; + lang.truncate(lang_territory.lastIndexOf('_')); // "en" + QTranslator qtTranslatorBase, qtTranslator, translatorBase, translator; + + qtTranslatorBase.load(QLibraryInfo::location(QLibraryInfo::TranslationsPath) + "/qt_" + lang); + if (!qtTranslatorBase.isEmpty()) + app.installTranslator(&qtTranslatorBase); + + qtTranslator.load(QLibraryInfo::location(QLibraryInfo::TranslationsPath) + "/qt_" + lang_territory); if (!qtTranslator.isEmpty()) app.installTranslator(&qtTranslator); - QTranslator translator; - translator.load(":/translations/"+locale); + + translatorBase.load(":/translations/"+lang); + if (!translatorBase.isEmpty()) + app.installTranslator(&translatorBase); + + translator.load(":/translations/"+lang_territory); if (!translator.isEmpty()) app.installTranslator(&translator); diff --git a/src/qt/bitcoin.qrc b/src/qt/bitcoin.qrc index 2985bb60e..145574df5 100644 --- a/src/qt/bitcoin.qrc +++ b/src/qt/bitcoin.qrc @@ -46,8 +46,11 @@ res/movies/update_spinner.mng - locale/bitcoin_de.qm - locale/bitcoin_nl.qm - locale/bitcoin_ru.qm + locale/bitcoin_de.qm + locale/bitcoin_es.qm + locale/bitcoin_es_CL.qm + locale/bitcoin_nb.qm + locale/bitcoin_nl.qm + locale/bitcoin_ru.qm