diff options
-rw-r--r-- | core/gettextfromc.cpp | 12 | ||||
-rw-r--r-- | desktop-widgets/mainwindow.cpp | 1 |
2 files changed, 9 insertions, 4 deletions
diff --git a/core/gettextfromc.cpp b/core/gettextfromc.cpp index fdb1e6d37..c3a592f5b 100644 --- a/core/gettextfromc.cpp +++ b/core/gettextfromc.cpp @@ -1,13 +1,17 @@ // SPDX-License-Identifier: GPL-2.0 #include "gettextfromc.h" #include <QHash> +#include <QMutex> static QHash<QByteArray, QByteArray> translationCache; +static QMutex lock; extern "C" const char *trGettext(const char *text) { - QByteArray &result = translationCache[QByteArray(text)]; - if (result.isEmpty()) - result = gettextFromC::tr(text).toUtf8(); - return result.constData(); + QByteArray key(text); + QMutexLocker l(&lock); + auto it = translationCache.find(key); + if (it == translationCache.end()) + it = translationCache.insert(key, gettextFromC::tr(text).toUtf8()); + return it->constData(); } diff --git a/desktop-widgets/mainwindow.cpp b/desktop-widgets/mainwindow.cpp index 95efcca63..b22b7e265 100644 --- a/desktop-widgets/mainwindow.cpp +++ b/desktop-widgets/mainwindow.cpp @@ -14,6 +14,7 @@ #include <QToolBar> #include <QStatusBar> +#include "core/gettextfromc.h" #include "core/version.h" #include "core/subsurface-string.h" #include "desktop-widgets/divelistview.h" |