summaryrefslogtreecommitdiff
path: root/src/main-view/LanguageMenu.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/main-view/LanguageMenu.cpp')
-rw-r--r--src/main-view/LanguageMenu.cpp64
1 files changed, 64 insertions, 0 deletions
diff --git a/src/main-view/LanguageMenu.cpp b/src/main-view/LanguageMenu.cpp
new file mode 100644
index 0000000..84ffd46
--- /dev/null
+++ b/src/main-view/LanguageMenu.cpp
@@ -0,0 +1,64 @@
+#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<QAction*>(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"));
+}