Changeset 14396 for trunk/qt/app.cc


Ignore:
Timestamp:
Dec 22, 2014, 1:08:19 AM (8 years ago)
Author:
mikedld
Message:

#4050: Use TRANSLATIONS_DIR macro as a hint for Qt client translation files location

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/qt/app.cc

    r14394 r14396  
    8181    MODEL_REFRESH_INTERVAL_MSEC   = 3000
    8282  };
     83
     84  bool
     85  loadTranslation (QTranslator& translator, const QString& name, const QString& localeName,
     86                   const QStringList& searchDirectories)
     87  {
     88    const QString filename = name + QLatin1Char ('_') + localeName;
     89    foreach (const QString& directory, searchDirectories)
     90    {
     91      if (translator.load (filename, directory))
     92        return true;
     93    }
     94
     95    return false;
     96  }
    8397}
    8498
     
    96110  setApplicationName (MY_CONFIG_NAME);
    97111
     112  const QString localeName = QLocale ().name ();
     113
    98114  // install the qt translator
    99   qtTranslator.load ("qt_" + QLocale::system ().name (), QLibraryInfo::location (QLibraryInfo::TranslationsPath));
    100   installTranslator (&qtTranslator);
     115  if (loadTranslation (qtTranslator, QLatin1String ("qt"), localeName, QStringList ()
     116        << QLibraryInfo::location (QLibraryInfo::TranslationsPath)
     117#ifdef TRANSLATIONS_DIR
     118        << TRANSLATIONS_DIR
     119#endif
     120        << (applicationDirPath () + "/translations")
     121      ))
     122    installTranslator (&qtTranslator);
    101123
    102124  // install the transmission translator
    103   appTranslator.load (QString (MY_CONFIG_NAME) + "_" + QLocale::system ().name (), QCoreApplication::applicationDirPath () + "/translations");
    104   installTranslator (&appTranslator);
     125  if (loadTranslation (appTranslator, MY_CONFIG_NAME, localeName, QStringList ()
     126#ifdef TRANSLATIONS_DIR
     127        << TRANSLATIONS_DIR
     128#endif
     129        << (applicationDirPath () + "/translations")
     130      ))
     131    installTranslator (&appTranslator);
    105132
    106133  Formatter::initUnits ();
Note: See TracChangeset for help on using the changeset viewer.