54 lines
1.5 KiB
C++
54 lines
1.5 KiB
C++
|
|
#include "TranslationHelper.h"
|
||
|
|
|
||
|
|
#include <QCoreApplication>
|
||
|
|
#include <QDir>
|
||
|
|
|
||
|
|
namespace
|
||
|
|
{
|
||
|
|
constexpr auto kSimplifiedChineseCatalog =
|
||
|
|
":/simcae/update-client/i18n/update-client_zh_CN.qm";
|
||
|
|
constexpr auto kQtSimplifiedChineseCatalog = "translations/qt_zh_CN.qm";
|
||
|
|
|
||
|
|
bool usesSimplifiedChinese(const QLocale& locale)
|
||
|
|
{
|
||
|
|
if (locale.language() != QLocale::Chinese ||
|
||
|
|
locale.script() == QLocale::TraditionalHanScript)
|
||
|
|
{
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
|
||
|
|
return locale.script() == QLocale::SimplifiedHanScript ||
|
||
|
|
locale.country() == QLocale::China ||
|
||
|
|
locale.country() == QLocale::Singapore;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
TranslationHelper::TranslationHelper()
|
||
|
|
{
|
||
|
|
m_simplifiedChineseCatalog.load(
|
||
|
|
QString::fromLatin1(kSimplifiedChineseCatalog));
|
||
|
|
}
|
||
|
|
|
||
|
|
bool TranslationHelper::installForSystemLocale()
|
||
|
|
{
|
||
|
|
if (!usesSimplifiedChinese(QLocale::system()) ||
|
||
|
|
m_simplifiedChineseCatalog.isEmpty())
|
||
|
|
{
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
|
||
|
|
const QString qtCatalogPath = QDir(QCoreApplication::applicationDirPath())
|
||
|
|
.filePath(QString::fromLatin1(
|
||
|
|
kQtSimplifiedChineseCatalog));
|
||
|
|
if (m_qtSimplifiedChineseCatalog.load(qtCatalogPath))
|
||
|
|
QCoreApplication::installTranslator(&m_qtSimplifiedChineseCatalog);
|
||
|
|
|
||
|
|
return QCoreApplication::installTranslator(&m_simplifiedChineseCatalog);
|
||
|
|
}
|
||
|
|
|
||
|
|
QString TranslationHelper::translate(const char* context,
|
||
|
|
const char* sourceText) const
|
||
|
|
{
|
||
|
|
return m_simplifiedChineseCatalog.translate(context, sourceText);
|
||
|
|
}
|