subsurface/gettextfromc.cpp
Maximilian Güntner 17fbb6b17f Support translating UTF8 strings
Interpreting UTF8 encoded strings using tr() instead of trUtf8()
and encoding the string back to utf8 again leads to serious encoding
errors.

Fixes #230

Signed-off-by: Maximilian Güntner <maximilian.guentner@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-11-15 13:13:15 +09:00

27 lines
552 B
C++

#include <QCoreApplication>
#include <QString>
#include <gettextfromc.h>
const char *gettextFromC::trGettext(const char *text)
{
QByteArray &result = translationCache[QByteArray(text)];
if (result.isEmpty())
result = trUtf8(text).toUtf8();
return result.constData();
}
void gettextFromC::reset(void)
{
translationCache.clear();
}
gettextFromC* gettextFromC::instance()
{
static gettextFromC *self = new gettextFromC();
return self;
}
extern "C" const char *trGettext(const char *text)
{
return gettextFromC::instance()->trGettext(text);
}