[Client] Restore language switching in SettingsView

Take over DlgSettings::updateLanguage: swap the QTranslator on
langChanged before any retranslateUi runs, so picking a language
applies immediately instead of waiting for a restart.
This commit is contained in:
Lukas Brübach 2026-10-11 14:57:28 +02:00
parent 3745c5d21d
commit 18cd13d196
2 changed files with 13 additions and 0 deletions

View file

@ -7,6 +7,7 @@
#include "../../../client/settings/cache_settings.h"
#include "../../pixel_map_generator.h"
#include "../main.h"
#include "../settings_page/abstract_settings_page.h"
#include "../settings_page/appearance_settings_page.h"
#include "../settings_page/deck_editor_settings_page.h"
@ -21,6 +22,7 @@
#include <QAbstractAnimation>
#include <QAbstractItemView>
#include <QApplication>
#include <QBrush>
#include <QColor>
#include <QCoreApplication>
@ -91,6 +93,10 @@ static QStringList pageIconResources()
SettingsView::SettingsView(QWidget *parent) : QWidget(parent), currentTabIndex(0), searchActive(false)
{
// Swap the QTranslator before retranslating (was DlgSettings::updateLanguage): without this, picking a new
// language only stores the setting and every retranslateUi re-runs against the old translator until restart.
// Connected before setupUi() so the swap runs before the pages' own langChanged handlers below.
connect(&SettingsCache::instance().personal(), &PersonalSettings::langChanged, this, &SettingsView::updateLanguage);
setupUi();
connect(&SettingsCache::instance().personal(), &PersonalSettings::langChanged, this, &SettingsView::retranslateUi);
@ -462,6 +468,12 @@ bool SettingsView::eventFilter(QObject *watched, QEvent *event)
return QWidget::eventFilter(watched, event);
}
void SettingsView::updateLanguage()
{
qApp->removeTranslator(translator); // NOLINT(cppcoreguidelines-pro-type-static-cast-downcast)
installNewTranslator();
}
void SettingsView::retranslateUi()
{
retranslateTabNames();

View file

@ -61,6 +61,7 @@ private slots:
void onTabClicked(int index);
void onSearchTextChanged(const QString &text);
void onSearchResultClicked(const QModelIndex &index);
void updateLanguage();
private:
// UI elements