From 6c66126bdb499da2c33045c0d85c58429764be18 Mon Sep 17 00:00:00 2001 From: James Turner Date: Wed, 29 Apr 2020 11:16:52 +0100 Subject: [PATCH] I18N: fix translation of nav-cache-init dialog Thanks to Slawek Mikula for spotting, that this was not working correctly, now it does. --- src/GUI/QtLauncher.cxx | 48 ++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 25 deletions(-) diff --git a/src/GUI/QtLauncher.cxx b/src/GUI/QtLauncher.cxx index c1e18e5ce..bb9aa3c4a 100644 --- a/src/GUI/QtLauncher.cxx +++ b/src/GUI/QtLauncher.cxx @@ -83,9 +83,24 @@ using std::string; namespace { // anonymous namespace +struct ProgressLabel { + NavDataCache::RebuildPhase phase; + const char* label; +}; + +static std::initializer_list progressStrings = { + {NavDataCache::REBUILD_READING_APT_DAT_FILES, QT_TRANSLATE_NOOP("initNavCache","Reading airport data")}, + {NavDataCache::REBUILD_LOADING_AIRPORTS, QT_TRANSLATE_NOOP("initNavCache","Loading airports")}, + {NavDataCache::REBUILD_FIXES, QT_TRANSLATE_NOOP("initNavCache","Loading waypoint data")}, + {NavDataCache::REBUILD_NAVAIDS, QT_TRANSLATE_NOOP("initNavCache","Loading navigation data")}, + {NavDataCache::REBUILD_POIS, QT_TRANSLATE_NOOP("initNavCache","Loading point-of-interest data")} +}; + void initNavCache() { - QString baseLabel = QT_TRANSLATE_NOOP("initNavCache", "Initialising navigation data, this may take several minutes"); + const char* baseLabelKey = QT_TRANSLATE_NOOP("initNavCache", "Initialising navigation data, this may take several minutes"); + QString baseLabel= qApp->translate("initNavCache", baseLabelKey); + NavDataCache* cache = NavDataCache::createInstance(); if (cache->isRebuildRequired()) { QProgressDialog rebuildProgress(baseLabel, @@ -106,37 +121,20 @@ void initNavCache() SGTimeStamp::sleepForMSec(50); phase = cache->rebuild(); - switch (phase) { - case NavDataCache::REBUILD_READING_APT_DAT_FILES: - rebuildProgress.setLabelText(QT_TRANSLATE_NOOP("initNavCache","Reading airport data")); - break; - - case NavDataCache::REBUILD_LOADING_AIRPORTS: - rebuildProgress.setLabelText(QT_TRANSLATE_NOOP("initNavCache","Loading airports")); - break; - - case NavDataCache::REBUILD_FIXES: - rebuildProgress.setLabelText(QT_TRANSLATE_NOOP("initNavCache","Loading waypoint data")); - break; - - case NavDataCache::REBUILD_NAVAIDS: - rebuildProgress.setLabelText(QT_TRANSLATE_NOOP("initNavCache","Loading navigation data")); - break; - - - case NavDataCache::REBUILD_POIS: - rebuildProgress.setLabelText(QT_TRANSLATE_NOOP("initNavCache","Loading point-of-interest data")); - break; - - default: + auto it = std::find_if(progressStrings.begin(), progressStrings.end(), [phase] + (const ProgressLabel& l) { return l.phase == phase; }); + if (it == progressStrings.end()) { rebuildProgress.setLabelText(baseLabel); + } else { + QString trans = qApp->translate("initNavCache", it->label); + rebuildProgress.setLabelText(trans); } if (phase == NavDataCache::REBUILD_UNKNOWN) { rebuildProgress.setValue(0); rebuildProgress.setMaximum(0); } else { - rebuildProgress.setValue(cache->rebuildPhaseCompletionPercentage()); + rebuildProgress.setValue(static_cast(cache->rebuildPhaseCompletionPercentage())); rebuildProgress.setMaximum(100); }