FluentUI/example/src/helper/TranslateHelper.cpp
朱子楚\zhuzi a3f375c9ef update
2024-04-11 14:51:43 +08:00

25 lines
748 B
C++

#include "TranslateHelper.h"
#include <QGuiApplication>
#include <QQmlEngine>
#include "SettingsHelper.h"
[[maybe_unused]] TranslateHelper::TranslateHelper(QObject *parent) : QObject(parent) {
_languages << "en_US";
_languages << "zh_CN";
_current = SettingsHelper::getInstance()->getLanguage();
}
TranslateHelper::~TranslateHelper() = default;
void TranslateHelper::init(QQmlEngine *engine) {
_engine = engine;
_translator = new QTranslator(this);
QGuiApplication::installTranslator(_translator);
QString translatorPath = QGuiApplication::applicationDirPath() + "/i18n";
if (_translator->load(QString::fromStdString("%1/example_%2.qm").arg(translatorPath, _current))) {
_engine->retranslate();
}
}