mirror of
https://github.com/yuzu-emu/yuzu-android.git
synced 2025-06-10 15:07:57 -05:00
yuzu: Port translation support from Citra
Co-Authored-By: Weiyi Wang <wwylele@gmail.com>
This commit is contained in:
@ -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) {
|
||||
|
Reference in New Issue
Block a user