mirror of
https://github.com/WinampDesktop/winamp.git
synced 2025-06-20 00:25:41 -04:00
FullscreenUI: Allow changing UI language
This commit is contained in:
@ -1648,32 +1648,29 @@ void MainWindow::setupAdditionalUi()
|
||||
}
|
||||
updateDebugMenuCropMode();
|
||||
|
||||
const QString current_language(QString::fromStdString(Host::GetBaseStringSettingValue("Main", "Language", "")));
|
||||
const std::string current_language = Host::GetBaseStringSettingValue("Main", "Language", "");
|
||||
QActionGroup* language_group = new QActionGroup(m_ui.menuSettingsLanguage);
|
||||
for (const std::pair<QString, QString>& it : QtHost::GetAvailableLanguageList())
|
||||
for (const auto& [language, code] : Host::GetAvailableLanguageList())
|
||||
{
|
||||
QAction* action = language_group->addAction(it.first);
|
||||
QAction* action = language_group->addAction(QString::fromUtf8(language));
|
||||
action->setCheckable(true);
|
||||
action->setChecked(current_language == it.second);
|
||||
action->setChecked(current_language == code);
|
||||
|
||||
QString icon_filename(QStringLiteral(":/icons/flags/%1.png").arg(it.second));
|
||||
QString icon_filename(QStringLiteral(":/icons/flags/%1.png").arg(QLatin1StringView(code)));
|
||||
if (!QFile::exists(icon_filename))
|
||||
{
|
||||
// try without the suffix (e.g. es-es -> es)
|
||||
const int pos = it.second.lastIndexOf('-');
|
||||
if (pos >= 0)
|
||||
icon_filename = QStringLiteral(":/icons/flags/%1.png").arg(it.second.left(pos));
|
||||
const char* pos = std::strrchr(code, '-');
|
||||
if (pos)
|
||||
icon_filename = QStringLiteral(":/icons/flags/%1.png").arg(QLatin1StringView(pos));
|
||||
}
|
||||
action->setIcon(QIcon(icon_filename));
|
||||
|
||||
m_ui.menuSettingsLanguage->addAction(action);
|
||||
action->setData(it.second);
|
||||
action->setData(QString::fromLatin1(code));
|
||||
connect(action, &QAction::triggered, [this, action]() {
|
||||
const QString new_language = action->data().toString();
|
||||
Host::SetBaseStringSettingValue("Main", "Language", new_language.toUtf8().constData());
|
||||
Host::CommitBaseSettingChanges();
|
||||
QtHost::InstallTranslator();
|
||||
recreate();
|
||||
Host::ChangeLanguage(new_language.toUtf8().constData());
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -107,6 +107,7 @@ public Q_SLOTS:
|
||||
std::optional<WindowInfo> getWindowInfo();
|
||||
|
||||
void checkForUpdates(bool display_message);
|
||||
void recreate();
|
||||
|
||||
void* getNativeWindowId();
|
||||
|
||||
@ -242,7 +243,6 @@ private:
|
||||
void setTheme(const QString& theme);
|
||||
void updateTheme();
|
||||
void reloadThemeSpecificImages();
|
||||
void recreate();
|
||||
void destroySubWindows();
|
||||
|
||||
void registerForDeviceNotifications();
|
||||
|
@ -253,9 +253,6 @@ bool InNoGUIMode();
|
||||
/// Executes a function on the UI thread.
|
||||
void RunOnUIThread(const std::function<void()>& func, bool block = false);
|
||||
|
||||
/// Returns a list of supported languages and codes (suffixes for translation files).
|
||||
std::vector<std::pair<QString, QString>> GetAvailableLanguageList();
|
||||
|
||||
/// Default language for the platform.
|
||||
const char* GetDefaultLanguage();
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
// SPDX-FileCopyrightText: 2019-2023 Connor McLaughlin <stenzek@gmail.com> and contributors.
|
||||
// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0)
|
||||
|
||||
#include "mainwindow.h"
|
||||
#include "qthost.h"
|
||||
|
||||
#include "core/host.h"
|
||||
@ -202,24 +203,37 @@ static std::string QtHost::GetFontPath(const GlyphInfo* gi)
|
||||
return font_path;
|
||||
}
|
||||
|
||||
std::vector<std::pair<QString, QString>> QtHost::GetAvailableLanguageList()
|
||||
std::span<const std::pair<const char*, const char*>> Host::GetAvailableLanguageList()
|
||||
{
|
||||
return {{QStringLiteral("English"), QStringLiteral("en")},
|
||||
{QStringLiteral("Deutsch"), QStringLiteral("de")},
|
||||
{QStringLiteral("Español de Latinoamérica"), QStringLiteral("es")},
|
||||
{QStringLiteral("Español de España"), QStringLiteral("es-ES")},
|
||||
{QStringLiteral("Français"), QStringLiteral("fr")},
|
||||
{QStringLiteral("עברית"), QStringLiteral("he")},
|
||||
{QStringLiteral("日本語"), QStringLiteral("ja")},
|
||||
{QStringLiteral("한국어"), QStringLiteral("ko")},
|
||||
{QStringLiteral("Italiano"), QStringLiteral("it")},
|
||||
{QStringLiteral("Nederlands"), QStringLiteral("nl")},
|
||||
{QStringLiteral("Polski"), QStringLiteral("pl")},
|
||||
{QStringLiteral("Português (Pt)"), QStringLiteral("pt-PT")},
|
||||
{QStringLiteral("Português (Br)"), QStringLiteral("pt-BR")},
|
||||
{QStringLiteral("Русский"), QStringLiteral("ru")},
|
||||
{QStringLiteral("Türkçe"), QStringLiteral("tr")},
|
||||
{QStringLiteral("简体中文"), QStringLiteral("zh-CN")}};
|
||||
static constexpr const std::pair<const char*, const char*> languages[] = {{"English", "en"},
|
||||
{"Deutsch", "de"},
|
||||
{"Español de Latinoamérica", "es"},
|
||||
{"Español de España", "es-ES"},
|
||||
{"Français", "fr"},
|
||||
{"עברית", "he"},
|
||||
{"日本語", "ja"},
|
||||
{"한국어", "ko"},
|
||||
{"Italiano", "it"},
|
||||
{"Nederlands", "nl"},
|
||||
{"Polski", "pl"},
|
||||
{"Português (Pt)", "pt-PT"},
|
||||
{"Português (Br)", "pt-BR"},
|
||||
{"Русский", "ru"},
|
||||
{"Türkçe", "tr"},
|
||||
{"简体中文", "zh-CN"}};
|
||||
|
||||
return languages;
|
||||
}
|
||||
|
||||
bool Host::ChangeLanguage(const char* new_language)
|
||||
{
|
||||
QtHost::RunOnUIThread([new_language = std::string(new_language)]() {
|
||||
Host::SetBaseStringSettingValue("Main", "Language", new_language.c_str());
|
||||
Host::CommitBaseSettingChanges();
|
||||
QtHost::InstallTranslator();
|
||||
g_main_window->recreate();
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
const char* QtHost::GetDefaultLanguage()
|
||||
|
@ -186,8 +186,8 @@ void SetupWizardDialog::setupLanguagePage()
|
||||
GeneralSettingsWidget::DEFAULT_THEME_NAME, "InterfaceSettingsWidget");
|
||||
connect(m_ui.theme, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &SetupWizardDialog::themeChanged);
|
||||
|
||||
for (const std::pair<QString, QString>& it : QtHost::GetAvailableLanguageList())
|
||||
m_ui.language->addItem(it.first, it.second);
|
||||
for (const auto& [language, code] : Host::GetAvailableLanguageList())
|
||||
m_ui.language->addItem(QString::fromUtf8(language), QString::fromLatin1(code));
|
||||
SettingWidgetBinder::BindWidgetToStringSetting(nullptr, m_ui.language, "Main", "Language",
|
||||
QtHost::GetDefaultLanguage());
|
||||
connect(m_ui.language, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
|
||||
|
Reference in New Issue
Block a user