From d20f40184f850b3ec9cea7e707ac4f3ae4bfdbf9 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Sat, 5 May 2018 19:58:18 +0800 Subject: [PATCH 1/3] Fix translation strings not found The translation context doesn't exist, so the translations were not found, fixed now. Closes #8829. --- src/base/search/searchpluginmanager.cpp | 25 ++++++++++++------------- src/base/search/searchpluginmanager.h | 1 - 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/base/search/searchpluginmanager.cpp b/src/base/search/searchpluginmanager.cpp index 89d08c98e..b1df35c92 100644 --- a/src/base/search/searchpluginmanager.cpp +++ b/src/base/search/searchpluginmanager.cpp @@ -62,18 +62,6 @@ namespace QPointer SearchPluginManager::m_instance = nullptr; -const QHash SearchPluginManager::m_categoryNames { - {"all", QT_TRANSLATE_NOOP("SearchEngine", "All categories")}, - {"movies", QT_TRANSLATE_NOOP("SearchEngine", "Movies")}, - {"tv", QT_TRANSLATE_NOOP("SearchEngine", "TV shows")}, - {"music", QT_TRANSLATE_NOOP("SearchEngine", "Music")}, - {"games", QT_TRANSLATE_NOOP("SearchEngine", "Games")}, - {"anime", QT_TRANSLATE_NOOP("SearchEngine", "Anime")}, - {"software", QT_TRANSLATE_NOOP("SearchEngine", "Software")}, - {"pictures", QT_TRANSLATE_NOOP("SearchEngine", "Pictures")}, - {"books", QT_TRANSLATE_NOOP("SearchEngine", "Books")} -}; - SearchPluginManager::SearchPluginManager() : m_updateUrl(QString("http://searchplugins.qbittorrent.org/%1/engines/").arg(Utils::Misc::pythonVersion() >= 3 ? "nova3" : "nova")) { @@ -307,7 +295,18 @@ SearchHandler *SearchPluginManager::startSearch(const QString &pattern, const QS QString SearchPluginManager::categoryFullName(const QString &categoryName) { - return tr(m_categoryNames.value(categoryName).toUtf8().constData()); + static const QHash categoryTable { + {"all", tr("All categories")}, + {"movies", tr("Movies")}, + {"tv", tr("TV shows")}, + {"music", tr("Music")}, + {"games", tr("Games")}, + {"anime", tr("Anime")}, + {"software", tr("Software")}, + {"pictures", tr("Pictures")}, + {"books", tr("Books")} + }; + return categoryTable.value(categoryName); } QString SearchPluginManager::pluginFullName(const QString &pluginName) diff --git a/src/base/search/searchpluginmanager.h b/src/base/search/searchpluginmanager.h index 536d012c7..89294af83 100644 --- a/src/base/search/searchpluginmanager.h +++ b/src/base/search/searchpluginmanager.h @@ -111,7 +111,6 @@ private: static QString pluginPath(const QString &name); static QPointer m_instance; - static const QHash m_categoryNames; const QString m_updateUrl; From 9f809114f039bdb7703c7fc386424393cda43931 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Sat, 5 May 2018 20:26:55 +0800 Subject: [PATCH 2/3] Really fix translation in fspathedit QT_TRANSLATE_NOOP3 is a macro, so we cannot use a runtime string for the context argument. Fix up 1d778676cd35ccd87102c92790df339c01a13b88. --- src/gui/fspathedit.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/gui/fspathedit.cpp b/src/gui/fspathedit.cpp index f14bc99b7..2d18d0660 100644 --- a/src/gui/fspathedit.cpp +++ b/src/gui/fspathedit.cpp @@ -41,7 +41,6 @@ namespace { - const char i18nContext[] = "FileSystemPathEdit"; struct TrStringWithComment { const char *source; @@ -49,18 +48,18 @@ namespace QString tr() const { - return QCoreApplication::translate(i18nContext, source, comment); + return QCoreApplication::translate("FileSystemPathEdit", source, comment); } }; constexpr TrStringWithComment browseButtonBriefText = - QT_TRANSLATE_NOOP3(i18nContext, "...", "Launch file dialog button text (brief)"); + QT_TRANSLATE_NOOP3("FileSystemPathEdit", "...", "Launch file dialog button text (brief)"); constexpr TrStringWithComment browseButtonFullText = - QT_TRANSLATE_NOOP3(i18nContext, "&Browse...", "Launch file dialog button text (full)"); + QT_TRANSLATE_NOOP3("FileSystemPathEdit", "&Browse...", "Launch file dialog button text (full)"); constexpr TrStringWithComment defaultDialogCaptionForFile = - QT_TRANSLATE_NOOP3(i18nContext, "Choose a file", "Caption for file open/save dialog"); + QT_TRANSLATE_NOOP3("FileSystemPathEdit", "Choose a file", "Caption for file open/save dialog"); constexpr TrStringWithComment defaultDialogCaptionForDirectory = - QT_TRANSLATE_NOOP3(i18nContext, "Choose a folder", "Caption for directory open dialog"); + QT_TRANSLATE_NOOP3("FileSystemPathEdit", "Choose a folder", "Caption for directory open dialog"); } class FileSystemPathEdit::FileSystemPathEditPrivate From 203bafc4c3a10d4f1920f17050df5dea859659dd Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Sat, 5 May 2018 21:21:33 +0800 Subject: [PATCH 3/3] Revert commit Apparently the translations were working in previous state, but affected by lupdate issue: https://github.com/qbittorrent/qBittorrent/issues/8220#issuecomment-385712673 The reverts commit fb698896c9cd69f3c1c48c078cd43555a2033d5e. Closes #8831. --- src/base/bittorrent/torrenthandle.cpp | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/base/bittorrent/torrenthandle.cpp b/src/base/bittorrent/torrenthandle.cpp index 4f49f5c88..84413be48 100644 --- a/src/base/bittorrent/torrenthandle.cpp +++ b/src/base/bittorrent/torrenthandle.cpp @@ -156,8 +156,6 @@ const int TorrentHandle::MAX_SEEDING_TIME = 525600; // The following can be removed after one or two libtorrent releases on each branch. namespace { - const char i18nContext[] = "TorrentHandle"; - // new constructor is available template::value, int>::type = 0> T makeTorrentCreator(const libtorrent::torrent_info & ti) @@ -1476,8 +1474,8 @@ void TorrentHandle::handleStorageMovedFailedAlert(libtorrent::storage_moved_fail return; } - LogMsg(QCoreApplication::translate(i18nContext, "Could not move torrent: '%1'. Reason: %2") - .arg(name(), QString::fromStdString(p->message())), Log::CRITICAL); + LogMsg(tr("Could not move torrent: '%1'. Reason: %2") + .arg(name(), QString::fromStdString(p->message())), Log::CRITICAL); m_moveStorageInfo.newPath.clear(); if (!m_moveStorageInfo.queuedPath.isEmpty()) { @@ -1649,19 +1647,18 @@ void TorrentHandle::handleSaveResumeDataFailedAlert(libtorrent::save_resume_data void TorrentHandle::handleFastResumeRejectedAlert(libtorrent::fastresume_rejected_alert *p) { qDebug("/!\\ Fast resume failed for %s, reason: %s", qUtf8Printable(name()), p->message().c_str()); - Logger *const logger = Logger::instance(); updateStatus(); if (p->error.value() == libt::errors::mismatching_file_size) { // Mismatching file size (files were probably moved) - logger->addMessage(QCoreApplication::translate(i18nContext, "File sizes mismatch for torrent '%1', pausing it.").arg(name()), Log::CRITICAL); + LogMsg(tr("File sizes mismatch for torrent '%1', pausing it.").arg(name()), Log::CRITICAL); m_hasMissingFiles = true; if (!isPaused()) pause(); } else { - logger->addMessage(QCoreApplication::translate(i18nContext, "Fast resume data was rejected for torrent '%1'. Reason: %2. Checking again...") - .arg(name(), QString::fromStdString(p->message())), Log::CRITICAL); + LogMsg(tr("Fast resume data was rejected for torrent '%1'. Reason: %2. Checking again...") + .arg(name(), QString::fromStdString(p->message())), Log::CRITICAL); } }