From d4b96557b8ee95520e44dfcf2329026779cf63bb Mon Sep 17 00:00:00 2001 From: Kleidis <167202775+kleidis@users.noreply.github.com> Date: Thu, 24 Oct 2024 03:41:41 +0200 Subject: [PATCH 1/2] lime_qt: Switch to `GetUserDefaultUILanguage` to fetch active display language on Windows --- src/citra_qt/citra_qt.cpp | 30 +++++++++++++++++++++++------- src/citra_qt/citra_qt.h | 3 +++ 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/citra_qt/citra_qt.cpp b/src/citra_qt/citra_qt.cpp index 487f38587..89458e153 100644 --- a/src/citra_qt/citra_qt.cpp +++ b/src/citra_qt/citra_qt.cpp @@ -3515,16 +3515,32 @@ void GMainWindow::LoadTranslation() { return; } - bool loaded; + QString language = UISettings::values.language; - if (UISettings::values.language.isEmpty()) { - // Use the system's default locale - loaded = translator.load(QLocale::system(), {}, {}, QStringLiteral(":/languages/")); - } else { - // Otherwise load from the specified file - loaded = translator.load(UISettings::values.language, QStringLiteral(":/languages/")); + if (language.isEmpty()) { +#ifdef _WIN32 + // Use Windows API to get the active display language + LANGID lang_id = GetUserDefaultUILanguage(); + wchar_t locale_name[LOCALE_NAME_MAX_LENGTH]; + + if (LCIDToLocaleName(MAKELCID(lang_id, SORT_DEFAULT), locale_name, LOCALE_NAME_MAX_LENGTH, + 0)) { + char locale_name_str[LOCALE_NAME_MAX_LENGTH]; + WideCharToMultiByte(CP_UTF8, 0, locale_name, -1, locale_name_str, + LOCALE_NAME_MAX_LENGTH, nullptr, nullptr); + language = QString::fromUtf8(locale_name_str); + } else { + language = QLocale::system().name(); + } +#else + language = QLocale::system().name(); +#endif } + // Replace dashes with underscores for compatibility with translation files + language.replace(QLatin1Char('-'), QLatin1Char('_')); + + bool loaded = translator.load(language, QStringLiteral(":/languages/")); if (loaded) { qApp->installTranslator(&translator); } else { diff --git a/src/citra_qt/citra_qt.h b/src/citra_qt/citra_qt.h index 078d254b5..161dc2b46 100644 --- a/src/citra_qt/citra_qt.h +++ b/src/citra_qt/citra_qt.h @@ -321,6 +321,9 @@ private: GameListPlaceholder* game_list_placeholder; LoadingScreen* loading_screen; + // General + QString current_language; + // Status bar elements QProgressBar* progress_bar = nullptr; QLabel* message_label = nullptr; From 4d1a2c75c6c205601763aac07085f58cacb7f5be Mon Sep 17 00:00:00 2001 From: Kleidis <167202775+kleidis@users.noreply.github.com> Date: Thu, 24 Oct 2024 15:17:55 +0200 Subject: [PATCH 2/2] Remove useless variable and cleanup comments --- src/citra_qt/citra_qt.cpp | 3 +-- src/citra_qt/citra_qt.h | 3 --- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/src/citra_qt/citra_qt.cpp b/src/citra_qt/citra_qt.cpp index 89458e153..a4264f51b 100644 --- a/src/citra_qt/citra_qt.cpp +++ b/src/citra_qt/citra_qt.cpp @@ -3519,7 +3519,6 @@ void GMainWindow::LoadTranslation() { if (language.isEmpty()) { #ifdef _WIN32 - // Use Windows API to get the active display language LANGID lang_id = GetUserDefaultUILanguage(); wchar_t locale_name[LOCALE_NAME_MAX_LENGTH]; @@ -3537,7 +3536,7 @@ void GMainWindow::LoadTranslation() { #endif } - // Replace dashes with underscores for compatibility with translation files + // For compatibility with translation files language.replace(QLatin1Char('-'), QLatin1Char('_')); bool loaded = translator.load(language, QStringLiteral(":/languages/")); diff --git a/src/citra_qt/citra_qt.h b/src/citra_qt/citra_qt.h index 161dc2b46..078d254b5 100644 --- a/src/citra_qt/citra_qt.h +++ b/src/citra_qt/citra_qt.h @@ -321,9 +321,6 @@ private: GameListPlaceholder* game_list_placeholder; LoadingScreen* loading_screen; - // General - QString current_language; - // Status bar elements QProgressBar* progress_bar = nullptr; QLabel* message_label = nullptr;