Qt: Enable switching of languages without restarting app

This commit is contained in:
Connor McLaughlin 2021-08-16 14:06:54 +10:00
parent 47f85dc453
commit 35bb20e586
3 changed files with 18 additions and 3 deletions

View file

@ -970,8 +970,8 @@ void MainWindow::setupAdditionalUi()
connect(action, &QAction::triggered, [this, action]() {
const QString new_language = action->data().toString();
m_host_interface->SetStringSettingValue("Main", "Language", new_language.toUtf8().constData());
QMessageBox::information(this, tr("DuckStation"),
tr("Language changed. Please restart the application to apply."));
m_host_interface->reinstallTranslator();
recreate();
});
}

View file

@ -158,7 +158,20 @@ void QtHostInterface::installTranslator()
}
Log_InfoPrintf("Loaded translation file for language '%s'", language.c_str());
qApp->installTranslator(translator.release());
qApp->installTranslator(translator.get());
m_translators.push_back(translator.release());
}
void QtHostInterface::reinstallTranslator()
{
for (QTranslator* translator : m_translators)
{
qApp->removeTranslator(translator);
translator->deleteLater();
}
m_translators.clear();
installTranslator();
}
void QtHostInterface::ReportError(const char* message)

View file

@ -91,6 +91,7 @@ public:
void setMainWindow(MainWindow* window);
HostDisplay* createHostDisplay();
void connectDisplaySignals(QtDisplayWidget* widget);
void reinstallTranslator();
void populateLoadStateMenu(const char* game_code, QMenu* menu);
void populateSaveStateMenu(const char* game_code, QMenu* menu);
@ -285,6 +286,7 @@ private:
QTimer* m_background_controller_polling_timer = nullptr;
std::unique_ptr<QTimer> m_settings_save_timer;
std::vector<QTranslator*> m_translators;
bool m_is_rendering_to_main = false;
bool m_is_fullscreen = false;