summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/gettextfromc.cpp12
1 files changed, 8 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();
}