#include "LanguageMenu.h" #include "../main.h" #include "../strings.h" LanguageMenu::LanguageMenu(QMenu* parent): QMenu(tr("&Language"), parent), locale(QSettings().value("lang").toString()), systemLocale(QLocale::system().name().split("_").first()) { initUi(parent); initLangs(); createActionsGroup(); foreach(QString key, langs.keys()) createAction(key); } void LanguageMenu::initUi(QMenu* parent) { parent->addMenu(this); setIcon(QIcon(":/images/language.png")); } void LanguageMenu::initLangs() { langs["cs"] = "Čeština (Czech)"; langs["fi"] = "Suomi (Finnish)"; langs["fr"] = "Français (French)"; langs["de"] = "Deutsch (German)"; langs["en"] = "English"; langs["ru"] = "Русский (Russian)"; langs["es"] = "Español (Spanish)"; langs["uk"] = "Українська (Ukrainian)"; langs[""] = tr("System") + ": " + langs[systemLocale]; } void LanguageMenu::createActionsGroup() { actionsGroup = new QActionGroup(this); actionsGroup->setExclusive(true); } void LanguageMenu::createAction(const QString& key) { QAction* action = addAction(langs[key]); action->setCheckable(true); if(key == locale) action->setChecked(true); action->setData(key); actionsGroup->addAction(action); connect(action, SIGNAL(triggered()), SLOT(saveLanguage())); } void LanguageMenu::saveLanguage() { QAction *action = qobject_cast(sender()); QString newLocale = action->data().toString(); QSettings().setValue("lang", newLocale); if(newLocale.isEmpty()) newLocale = systemLocale; installTranslator("freshmemory_" + newLocale, getResourcePath() + "/tr"); QMessageBox::information(this, Strings::tr(Strings::s_appTitle), tr("The application must be restarted to use the selected language")); }