From 879cb73b8bda364f63cc97c0f9963cfddc581add Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Sun, 17 Jun 2018 21:03:16 +0200 Subject: 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 --- core/gettextfromc.cpp | 25 +++++-------------------- core/gettextfromc.h | 6 ------ 2 files changed, 5 insertions(+), 26 deletions(-) (limited to 'core') 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 -#include #include "gettextfromc.h" +#include -const char *gettextFromC::trGettext(const char *text) +static QHash 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); -} diff --git a/core/gettextfromc.h b/core/gettextfromc.h index 5f22d8647..647ea52a8 100644 --- a/core/gettextfromc.h +++ b/core/gettextfromc.h @@ -2,18 +2,12 @@ #ifndef GETTEXTFROMC_H #define GETTEXTFROMC_H -#include #include extern "C" const char *trGettext(const char *text); class gettextFromC { Q_DECLARE_TR_FUNCTIONS(gettextFromC) -public: - static gettextFromC *instance(); - const char *trGettext(const char *text); - void reset(void); - QHash translationCache; }; #endif // GETTEXTFROMC_H -- cgit v1.2.3-70-g09d2