diff options
| author | David <25727384+ogniK5377@users.noreply.github.com> | 2020-07-18 22:43:37 +1000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-07-18 22:43:37 +1000 |
| commit | 9943a478fe19dad4f770292b989179f71e2d10a0 (patch) | |
| tree | 7c1f7d2edc8841e5e9ac2c9a49da0d4314a3f8b2 /src/yuzu/main.cpp | |
| parent | 4a8cb9a70671db5684dadf10061f3c3cf1d27741 (diff) | |
| parent | 4450a2688a8507dfece913e5c224bb497191ec7e (diff) | |
Merge pull request #3349 from FearlessTobi/translationnns
[WIP] yuzu: Port translation support from Citra v2
Diffstat (limited to 'src/yuzu/main.cpp')
| -rw-r--r-- | src/yuzu/main.cpp | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index 6909d65d0..31a635176 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp @@ -191,6 +191,8 @@ GMainWindow::GMainWindow() provider(std::make_unique<FileSys::ManualContentProvider>()) { InitializeLogging(); + LoadTranslation(); + setAcceptDrops(true); ui.setupUi(this); statusBar()->hide(); @@ -2048,6 +2050,9 @@ void GMainWindow::OnConfigure() { const bool old_discord_presence = UISettings::values.enable_discord_presence; ConfigureDialog configure_dialog(this, hotkey_registry); + connect(&configure_dialog, &ConfigureDialog::LanguageChanged, this, + &GMainWindow::OnLanguageChanged); + const auto result = configure_dialog.exec(); if (result != QDialog::Accepted) { return; @@ -2620,6 +2625,43 @@ void GMainWindow::UpdateUITheme() { QIcon::setThemeSearchPaths(theme_paths); } +void GMainWindow::LoadTranslation() { + // If the selected language is English, no need to install any translation + if (UISettings::values.language == QStringLiteral("en")) { + return; + } + + bool loaded; + + if (UISettings::values.language.isEmpty()) { + // If the selected language is empty, use system locale + loaded = translator.load(QLocale(), {}, {}, QStringLiteral(":/languages/")); + } else { + // Otherwise load from the specified file + loaded = translator.load(UISettings::values.language, QStringLiteral(":/languages/")); + } + + if (loaded) { + qApp->installTranslator(&translator); + } else { + UISettings::values.language = QStringLiteral("en"); + } +} + +void GMainWindow::OnLanguageChanged(const QString& locale) { + if (UISettings::values.language != QStringLiteral("en")) { + qApp->removeTranslator(&translator); + } + + UISettings::values.language = locale; + LoadTranslation(); + ui.retranslateUi(this); + UpdateWindowTitle(); + + if (emulation_running) + ui.action_Start->setText(tr("Continue")); +} + void GMainWindow::SetDiscordEnabled([[maybe_unused]] bool state) { #ifdef USE_DISCORD_PRESENCE if (state) { |
