#include "languageswitcher.h"
#include <QTranslator>
#include "event/EventCenter.h"

LanguageSwitcher* LanguageSwitcher::lsw = Q_NULLPTR;

LanguageSwitcher* LanguageSwitcher::Instance()
{
	if (lsw == Q_NULLPTR)
	{
		lsw = new LanguageSwitcher();

	}
	return lsw;
}
LanguageSwitcher::LanguageSwitcher()
{}

LanguageSwitcher::~LanguageSwitcher()
{}

void LanguageSwitcher::setTranslator(QTranslator* tra)
{
	this->translator = tra;
}

void LanguageSwitcher::setDefaultLanguage(QString str)
{
	QString lan = QString(":/translations/" + str + ".qm");
	if (translator->load(lan))
	{
		//qDebug() << "installTranslator";
		//QApplication::installTranslator(translator);
	}
	EventCenter::Default()->triggerEvent(ReloadLanguage, nullptr, nullptr);
}

