InterfacePane: add all interface languages

This commit is contained in:
Michael M 2017-07-17 14:49:51 -07:00
parent 030dc11c6e
commit b22ed9683d
1 changed files with 65 additions and 5 deletions

View File

@ -8,6 +8,7 @@
#include <QComboBox> #include <QComboBox>
#include <QFormLayout> #include <QFormLayout>
#include <QGroupBox> #include <QGroupBox>
#include <QMessageBox>
#include <QVBoxLayout> #include <QVBoxLayout>
#include <QWidget> #include <QWidget>
@ -19,6 +20,56 @@
#include "DolphinQt2/Settings.h" #include "DolphinQt2/Settings.h"
static QComboBox* MakeLanguageComboBox()
{
static const struct
{
const QString name;
const char* id;
} languages[] = {
{QStringLiteral("Bahasa Melayu"), "ms"}, // Malay
{QStringLiteral("Catal\u00E0"), "ca"}, // Catalan
{QStringLiteral("\u010Ce\u0161tina"), "cs"}, // Czech
{QStringLiteral("Dansk"), "da"}, // Danish
{QStringLiteral("Deutsch"), "de"}, // German
{QStringLiteral("English"), "en"}, // English
{QStringLiteral("Espa\u00F1ol"), "es"}, // Spanish
{QStringLiteral("Fran\u00E7ais"), "fr"}, // French
{QStringLiteral("Hrvatski"), "hr"}, // Croatian
{QStringLiteral("Italiano"), "it"}, // Italian
{QStringLiteral("Magyar"), "hu"}, // Hungarian
{QStringLiteral("Nederlands"), "nl"}, // Dutch
{QStringLiteral("Norsk bokm\u00E5l"), "nb"}, // Norwegian
{QStringLiteral("Polski"), "pl"}, // Polish
{QStringLiteral("Portugu\u00EAs"), "pt"}, // Portuguese
{QStringLiteral("Portugu\u00EAs (Brasil)"), "pt_BR"}, // Portuguese (Brazil)
{QStringLiteral("Rom\u00E2n\u0103"), "ro"}, // Romanian
{QStringLiteral("Srpski"), "sr"}, // Serbian
{QStringLiteral("Svenska"), "sv"}, // Swedish
{QStringLiteral("T\u00FCrk\u00E7e"), "tr"}, // Turkish
{QStringLiteral("\u0395\u03BB\u03BB\u03B7\u03BD\u03B9\u03BA\u03AC"), "el"}, // Greek
{QStringLiteral("\u0420\u0443\u0441\u0441\u043A\u0438\u0439"), "ru"}, // Russian
{QStringLiteral("\u0627\u0644\u0639\u0631\u0628\u064A\u0629"), "ar"}, // Arabic
{QStringLiteral("\u0641\u0627\u0631\u0633\u06CC"), "fa"}, // Farsi
{QStringLiteral("\uD55C\uAD6D\uC5B4"), "ko"}, // Korean
{QStringLiteral("\u65E5\u672C\u8A9E"), "ja"}, // Japanese
{QStringLiteral("\u7B80\u4F53\u4E2D\u6587"), "zh_CN"}, // Simplified Chinese
{QStringLiteral("\u7E41\u9AD4\u4E2D\u6587"), "zh_TW"}, // Traditional Chinese
};
auto* combobox = new QComboBox();
combobox->addItem(QObject::tr("<System Language>"), QStringLiteral(""));
for (const auto& lang : languages)
combobox->addItem(lang.name, QString::fromLatin1(lang.id));
// The default, QComboBox::AdjustToContentsOnFirstShow, causes a noticeable pause when opening the
// SettingWindow for the first time. The culprit seems to be non-Latin graphemes in the above
// list. QComboBox::AdjustToContents still has some lag but it's much less noticeable.
combobox->setSizeAdjustPolicy(QComboBox::AdjustToContents);
return combobox;
}
InterfacePane::InterfacePane(QWidget* parent) : QWidget(parent) InterfacePane::InterfacePane(QWidget* parent) : QWidget(parent)
{ {
CreateLayout(); CreateLayout();
@ -48,9 +99,7 @@ void InterfacePane::CreateUI()
auto* combobox_layout = new QFormLayout; auto* combobox_layout = new QFormLayout;
groupbox_layout->addLayout(combobox_layout); groupbox_layout->addLayout(combobox_layout);
m_combobox_language = new QComboBox; m_combobox_language = MakeLanguageComboBox();
// TODO: Support more languages other then English
m_combobox_language->addItem(tr("English"));
combobox_layout->addRow(tr("&Language:"), m_combobox_language); combobox_layout->addRow(tr("&Language:"), m_combobox_language);
// Theme Combobox // Theme Combobox
@ -111,8 +160,8 @@ void InterfacePane::ConnectLayout()
&InterfacePane::OnSaveConfig); &InterfacePane::OnSaveConfig);
connect(m_combobox_theme, static_cast<void (QComboBox::*)(const QString&)>(&QComboBox::activated), connect(m_combobox_theme, static_cast<void (QComboBox::*)(const QString&)>(&QComboBox::activated),
&Settings::Instance(), &Settings::SetThemeName); &Settings::Instance(), &Settings::SetThemeName);
connect(m_combobox_language, static_cast<void (QComboBox::*)(int)>(&QComboBox::activated), connect(m_combobox_language, static_cast<void (QComboBox::*)(int)>(&QComboBox::activated), this,
[this](int index) { OnSaveConfig(); }); &InterfacePane::OnSaveConfig);
connect(m_checkbox_confirm_on_stop, &QCheckBox::clicked, this, &InterfacePane::OnSaveConfig); connect(m_checkbox_confirm_on_stop, &QCheckBox::clicked, this, &InterfacePane::OnSaveConfig);
connect(m_checkbox_use_panic_handlers, &QCheckBox::clicked, this, &InterfacePane::OnSaveConfig); connect(m_checkbox_use_panic_handlers, &QCheckBox::clicked, this, &InterfacePane::OnSaveConfig);
connect(m_checkbox_enable_osd, &QCheckBox::clicked, this, &InterfacePane::OnSaveConfig); connect(m_checkbox_enable_osd, &QCheckBox::clicked, this, &InterfacePane::OnSaveConfig);
@ -128,6 +177,8 @@ void InterfacePane::LoadConfig()
m_checkbox_top_window->setChecked(startup_params.bKeepWindowOnTop); m_checkbox_top_window->setChecked(startup_params.bKeepWindowOnTop);
m_checkbox_render_to_window->setChecked(startup_params.bRenderToMain); m_checkbox_render_to_window->setChecked(startup_params.bRenderToMain);
m_checkbox_use_builtin_title_database->setChecked(startup_params.m_use_builtin_title_database); m_checkbox_use_builtin_title_database->setChecked(startup_params.m_use_builtin_title_database);
m_combobox_language->setCurrentIndex(m_combobox_language->findData(
QString::fromStdString(SConfig::GetInstance().m_InterfaceLanguage)));
m_combobox_theme->setCurrentIndex( m_combobox_theme->setCurrentIndex(
m_combobox_theme->findText(QString::fromStdString(SConfig::GetInstance().theme_name))); m_combobox_theme->findText(QString::fromStdString(SConfig::GetInstance().theme_name)));
@ -155,5 +206,14 @@ void InterfacePane::OnSaveConfig()
settings.m_show_active_title = m_checkbox_show_active_title->isChecked(); settings.m_show_active_title = m_checkbox_show_active_title->isChecked();
settings.m_PauseOnFocusLost = m_checkbox_pause_on_focus_lost->isChecked(); settings.m_PauseOnFocusLost = m_checkbox_pause_on_focus_lost->isChecked();
auto new_language = m_combobox_language->currentData().toString().toStdString();
if (new_language != SConfig::GetInstance().m_InterfaceLanguage)
{
SConfig::GetInstance().m_InterfaceLanguage = new_language;
QMessageBox::information(
this, tr("Restart Required"),
tr("You must restart Dolphin in order for the change to take effect."));
}
settings.SaveSettings(); settings.SaveSettings();
} }