Ignore:
Timestamp:
Nov 15, 2015, 11:03:27 AM (7 years ago)
Author:
mikedld
Message:

Fallback to English if no proper translation is available

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/qt/Application.cc

    r14580 r14600  
    4444  const QString DBUS_INTERFACE   = QString::fromUtf8 ("com.transmissionbt.Transmission" );
    4545
    46   const char * MY_READABLE_NAME ("transmission-qt");
     46  const QLatin1String MY_CONFIG_NAME ("transmission");
     47  const QLatin1String MY_READABLE_NAME ("transmission-qt");
    4748
    4849  const tr_option opts[] =
     
    9697  myLastFullUpdateTime (0)
    9798{
    98   const QString MY_CONFIG_NAME = QString::fromUtf8 ("transmission");
    99 
    10099  setApplicationName (MY_CONFIG_NAME);
    101 
    102   const QString localeName = QLocale ().name ();
    103 
    104   // install the qt translator
    105   if (loadTranslation (qtTranslator, QLatin1String ("qt"), localeName, QStringList ()
    106         << QLibraryInfo::location (QLibraryInfo::TranslationsPath)
    107 #ifdef TRANSLATIONS_DIR
    108         << QString::fromUtf8 (TRANSLATIONS_DIR)
    109 #endif
    110         << (applicationDirPath () + QLatin1String ("/translations"))
    111       ))
    112     installTranslator (&qtTranslator);
    113 
    114   // install the transmission translator
    115   if (loadTranslation (appTranslator, MY_CONFIG_NAME, localeName, QStringList ()
    116 #ifdef TRANSLATIONS_DIR
    117         << QString::fromUtf8 (TRANSLATIONS_DIR)
    118 #endif
    119         << (applicationDirPath () + QLatin1String ("/translations"))
    120       ))
    121     installTranslator (&appTranslator);
     100  loadTranslations ();
    122101
    123102  Formatter::initUnits ();
     
    164143          case 'm': minimized = true; break;
    165144          case 'v':
    166             std::cerr << MY_READABLE_NAME << ' ' << LONG_VERSION_STRING << std::endl;
     145            std::cerr << MY_READABLE_NAME.latin1 () << ' ' << LONG_VERSION_STRING << std::endl;
    167146            quitLater ();
    168147            return;
    169148          case TR_OPT_ERR:
    170149            std::cerr << qPrintable(QObject::tr ("Invalid option")) << std::endl;
    171             tr_getopt_usage (MY_READABLE_NAME, getUsage (), opts);
     150            tr_getopt_usage (MY_READABLE_NAME.latin1 (), getUsage (), opts);
    172151            quitLater ();
    173152            return;
     
    332311
    333312void
     313Application::loadTranslations ()
     314{
     315  const QStringList qtQmDirs = QStringList () <<
     316    QLibraryInfo::location (QLibraryInfo::TranslationsPath) <<
     317#ifdef TRANSLATIONS_DIR
     318    QString::fromUtf8 (TRANSLATIONS_DIR) <<
     319#endif
     320    (applicationDirPath () + QLatin1String ("/translations"));
     321
     322  const QStringList appQmDirs = QStringList () <<
     323#ifdef TRANSLATIONS_DIR
     324    QString::fromUtf8 (TRANSLATIONS_DIR) <<
     325#endif
     326    (applicationDirPath () + QLatin1String ("/translations"));
     327
     328  QString localeName = QLocale ().name ();
     329
     330  if (!loadTranslation (myAppTranslator, MY_CONFIG_NAME, localeName, appQmDirs))
     331    {
     332      localeName = QLatin1String ("en");
     333      loadTranslation (myAppTranslator, MY_CONFIG_NAME, localeName, appQmDirs);
     334    }
     335
     336  if (loadTranslation (myQtTranslator, QLatin1String ("qt"), localeName, qtQmDirs))
     337    installTranslator (&myQtTranslator);
     338  installTranslator (&myAppTranslator);
     339}
     340
     341void
    334342Application::quitLater ()
    335343{
Note: See TracChangeset for help on using the changeset viewer.