diff options
-rw-r--r-- | gettextfromc.cpp | 12 | ||||
-rw-r--r-- | gettextfromc.h | 11 |
2 files changed, 17 insertions, 6 deletions
diff --git a/gettextfromc.cpp b/gettextfromc.cpp index fe6263a4b..de278afeb 100644 --- a/gettextfromc.cpp +++ b/gettextfromc.cpp @@ -2,9 +2,17 @@ #include <QString> #include <gettextfromc.h> -char *gettextFromC::gettext(const char *text) +const char *gettextFromC::gettext(const char *text) { - return strdup(tr(text).toLocal8Bit().data()); + QByteArray &result = translationCache[text]; + if (result.isEmpty()) + result = tr(text).toUtf8(); + return result.constData(); +} + +void gettextFromC::reset(void) +{ + translationCache.clear(); } gettextFromC* gettextFromC::instance() diff --git a/gettextfromc.h b/gettextfromc.h index 3852709c9..7d7bca142 100644 --- a/gettextfromc.h +++ b/gettextfromc.h @@ -1,6 +1,7 @@ -#ifndef GETTEXT_H -#define GETTEXT_H +#ifndef GETTEXTFROMC_H +#define GETTEXTFROMC_H +#include <QHash> extern "C" const char *gettext(const char *text); @@ -9,7 +10,9 @@ class gettextFromC Q_DECLARE_TR_FUNCTIONS(gettextFromC) public: static gettextFromC *instance(); - char *gettext(const char *text); + const char *gettext(const char *text); + void reset(void); + QHash <const char *, QByteArray> translationCache; }; -#endif // GETTEXT_H +#endif // GETTEXTFROMC_H |