diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2018-06-17 21:03:16 +0200 |
---|---|---|
committer | Tomaz Canabrava <tcanabrava@kde.org> | 2018-06-24 20:31:14 +0200 |
commit | 879cb73b8bda364f63cc97c0f9963cfddc581add (patch) | |
tree | 3f800beb71313141ad55b7131ef746a3083330b0 /core/gettextfromc.cpp | |
parent | 61b8add59078f3a55dc02dc63639173be03fdf41 (diff) | |
download | subsurface-879cb73b8bda364f63cc97c0f9963cfddc581add.tar.gz |
Localization: remove gettextFromC::instance()
There were a handfull instances of the kind
1) gettextFromC::instance()->tr(...)
2) gettextFromC::instance()->trGettext(...)
1) is pointless, as tr is a static function.
All instances of 2) were likewise pointless, because trGettext()
returns a C-string, which was then immediately converted to a
QString.
Thus, replace both constructs by gettextFromC::tr(...).
After this change there was only one user of gettextFromC::instance()
left, viz. the C-interface funtion trGettext(). Therefore, remove
gettextFromC::instance() and do all the caching / translating
directly in the global trGettext().
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'core/gettextfromc.cpp')
-rw-r--r-- | core/gettextfromc.cpp | 25 |
1 files changed, 5 insertions, 20 deletions
diff --git a/core/gettextfromc.cpp b/core/gettextfromc.cpp index e668fec2e..fdb1e6d37 100644 --- a/core/gettextfromc.cpp +++ b/core/gettextfromc.cpp @@ -1,28 +1,13 @@ // SPDX-License-Identifier: GPL-2.0 -#include <QCoreApplication> -#include <QString> #include "gettextfromc.h" +#include <QHash> -const char *gettextFromC::trGettext(const char *text) +static QHash<QByteArray, QByteArray> translationCache; + +extern "C" const char *trGettext(const char *text) { QByteArray &result = translationCache[QByteArray(text)]; if (result.isEmpty()) - result = translationCache[QByteArray(text)] = trUtf8(text).toUtf8(); + result = gettextFromC::tr(text).toUtf8(); return result.constData(); } - -void gettextFromC::reset(void) -{ - translationCache.clear(); -} - -gettextFromC *gettextFromC::instance() -{ - static gettextFromC self; - return &self; -} - -extern "C" const char *trGettext(const char *text) -{ - return gettextFromC::instance()->trGettext(text); -} |