summaryrefslogtreecommitdiffstats
path: root/core/qthelper.cpp
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2020-09-21 21:44:35 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2020-09-21 13:42:00 -0700
commit9d3b15bf9cb758e9f371d5f5f9eec0a3a2b0a4e2 (patch)
tree205328a2e44233bf21244dde08e28cc6a497b23c /core/qthelper.cpp
parent9ee85c0802ad2f54900e50c6cecf1ba99b7e120e (diff)
downloadsubsurface-9d3b15bf9cb758e9f371d5f5f9eec0a3a2b0a4e2.tar.gz
translations: initialize water type strings at run time
The water type strings were static and therefore passed through gettextFromC::tr() before main(). One would hope to get a warning in such a case, but this is not the case. Therefore, use the QT_TRANSLATE_NOOP macro to register the strings in Qt's translation system and translate the list when needed. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'core/qthelper.cpp')
-rw-r--r--core/qthelper.cpp31
1 files changed, 22 insertions, 9 deletions
diff --git a/core/qthelper.cpp b/core/qthelper.cpp
index 203234f05..f8c06d755 100644
--- a/core/qthelper.cpp
+++ b/core/qthelper.cpp
@@ -626,16 +626,34 @@ QString get_salinity_string(int salinity)
return QStringLiteral("%L1%2").arg(salinity / 10.0).arg(gettextFromC::tr("g/ℓ"));
}
+// the water types need to match the watertypes enum
+static const char *waterTypes[] = {
+ QT_TRANSLATE_NOOP("gettextFromC", "Fresh"),
+ QT_TRANSLATE_NOOP("gettextFromC", "Brackish"),
+ QT_TRANSLATE_NOOP("gettextFromC", "EN13319"),
+ QT_TRANSLATE_NOOP("gettextFromC", "Salt"),
+ QT_TRANSLATE_NOOP("gettextFromC", "Use DC")
+};
+
QString get_water_type_string(int salinity)
{
if (salinity < 10050)
- return waterTypes[FRESHWATER];
+ return gettextFromC::tr(waterTypes[FRESHWATER]);
else if (salinity < 10190)
- return waterTypes[BRACKISHWATER];
+ return gettextFromC::tr(waterTypes[BRACKISHWATER]);
else if (salinity < 10210)
- return waterTypes[EN13319WATER];
+ return gettextFromC::tr(waterTypes[EN13319WATER]);
else
- return waterTypes[SALTWATER];
+ return gettextFromC::tr(waterTypes[SALTWATER]);
+}
+
+QStringList getWaterTypesAsString()
+{
+ QStringList res;
+ res.reserve(std::end(waterTypes) - std::begin(waterTypes)); // Waiting for C++17's std::size()
+ for (const char *t: waterTypes)
+ res.push_back(gettextFromC::tr(t));
+ return res;
}
QString getSubsurfaceDataPath(QString folderToFind)
@@ -1178,11 +1196,6 @@ QString localFilePath(const QString &originalFilename)
return localFilenameOf.value(originalFilename, originalFilename);
}
-// the water types need to match the watertypes enum
-const QStringList waterTypes = {
- gettextFromC::tr("Fresh"), gettextFromC::tr("Brackish"), gettextFromC::tr("EN13319"), gettextFromC::tr("Salt"), gettextFromC::tr("Use DC")
-};
-
// TODO: Apparently Qt has no simple way of listing the supported video
// codecs? Do we have to query them by hand using QMediaPlayer::hasSupport()?
const QStringList videoExtensionsList = {