From 1eec889832476809dca42eea194b1342d6a884c4 Mon Sep 17 00:00:00 2001 From: Mike Gelfand Date: Mon, 22 Dec 2014 01:08:19 +0000 Subject: [PATCH] #4050: Use TRANSLATIONS_DIR macro as a hint for Qt client translation files location --- qt/CMakeLists.txt | 8 ++++++++ qt/app.cc | 35 +++++++++++++++++++++++++++++++---- 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/qt/CMakeLists.txt b/qt/CMakeLists.txt index bf5129be8..2ca17b95d 100644 --- a/qt/CMakeLists.txt +++ b/qt/CMakeLists.txt @@ -147,6 +147,10 @@ include_directories( ${EVENT2_INCLUDE_DIRS} ) +add_definitions( + "-DTRANSLATIONS_DIR=\"${CMAKE_INSTALL_FULL_DATADIR}/${TR_NAME}/translations\"" +) + add_executable(${TR_NAME}-qt ${${PROJECT_NAME}_SOURCES} ${${PROJECT_NAME}_UI_SOURCES} @@ -175,3 +179,7 @@ if(INSTALL_DOC) endif() install(FILES transmission-qt.desktop DESTINATION ${CMAKE_INSTALL_DATADIR}/applications) + +if(ENABLE_NLS) + install(FILES ${${PROJECT_NAME}_QM_FILES} DESTINATION ${CMAKE_INSTALL_DATADIR}/${TR_NAME}/translations) +endif() diff --git a/qt/app.cc b/qt/app.cc index f3c6c3cab..8eab9e33c 100644 --- a/qt/app.cc +++ b/qt/app.cc @@ -80,6 +80,20 @@ namespace SESSION_REFRESH_INTERVAL_MSEC = 3000, MODEL_REFRESH_INTERVAL_MSEC = 3000 }; + + bool + loadTranslation (QTranslator& translator, const QString& name, const QString& localeName, + const QStringList& searchDirectories) + { + const QString filename = name + QLatin1Char ('_') + localeName; + foreach (const QString& directory, searchDirectories) + { + if (translator.load (filename, directory)) + return true; + } + + return false; + } } MyApp::MyApp (int& argc, char ** argv): @@ -95,13 +109,26 @@ MyApp::MyApp (int& argc, char ** argv): setApplicationName (MY_CONFIG_NAME); + const QString localeName = QLocale ().name (); + // install the qt translator - qtTranslator.load ("qt_" + QLocale::system ().name (), QLibraryInfo::location (QLibraryInfo::TranslationsPath)); - installTranslator (&qtTranslator); + if (loadTranslation (qtTranslator, QLatin1String ("qt"), localeName, QStringList () + << QLibraryInfo::location (QLibraryInfo::TranslationsPath) +#ifdef TRANSLATIONS_DIR + << TRANSLATIONS_DIR +#endif + << (applicationDirPath () + "/translations") + )) + installTranslator (&qtTranslator); // install the transmission translator - appTranslator.load (QString (MY_CONFIG_NAME) + "_" + QLocale::system ().name (), QCoreApplication::applicationDirPath () + "/translations"); - installTranslator (&appTranslator); + if (loadTranslation (appTranslator, MY_CONFIG_NAME, localeName, QStringList () +#ifdef TRANSLATIONS_DIR + << TRANSLATIONS_DIR +#endif + << (applicationDirPath () + "/translations") + )) + installTranslator (&appTranslator); Formatter::initUnits ();