From aee51588141731a315f1d80b72c9ff883abef84c Mon Sep 17 00:00:00 2001 From: Charlie Fenton Date: Fri, 18 Aug 2023 01:31:21 -0700 Subject: [PATCH] Mac: Fix Automatic language detection --- clientgui/BOINCGUIApp.cpp | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/clientgui/BOINCGUIApp.cpp b/clientgui/BOINCGUIApp.cpp index df9aa21bade..860d7ba0023 100644 --- a/clientgui/BOINCGUIApp.cpp +++ b/clientgui/BOINCGUIApp.cpp @@ -21,6 +21,7 @@ #ifdef __WXMAC__ #include +#include #include "filesys.h" #include "util.h" #include "mac_util.h" @@ -207,12 +208,15 @@ bool CBOINCGUIApp::OnInit() { m_pConfig->Read(wxT("LanguageISO"), &m_strISOLanguageCode, wxT("")); m_bUseDefaultLocale = false; bool bUseDefaultLocaleDefault = false; -#ifdef __WXMAC__ // wxLocale::GetLanguageInfo(wxLANGUAGE_DEFAULT) does not work on Mac - wxLocale *defaultLocale = new wxLocale; - defaultLocale->Init(wxLANGUAGE_DEFAULT); - wxString defaultLanguageCode = defaultLocale->GetCanonicalName(); +#ifdef __WXMAC__ + // Because our translations don't use Apple's standard localization + // scheme, the Cocoa APIs used by wxLocale for wxLANGUAGE_DEFAULT + // always return English as the language for the reasons explained + // in https://stackoverflow.com/questions/48136456. The wxLocale + // documentation warns us to use wxUILocale::GetSystemLanguage(). + int systemLanguageCode = wxUILocale::GetSystemLanguage(); + wxString defaultLanguageCode = wxLocale::GetLanguageCanonicalName(systemLanguageCode); bUseDefaultLocaleDefault = m_strISOLanguageCode == defaultLanguageCode; - delete defaultLocale; #else const wxLanguageInfo *defaultLanguageInfo = wxLocale::GetLanguageInfo(wxLANGUAGE_DEFAULT); if (defaultLanguageInfo != NULL) { @@ -296,6 +300,16 @@ bool CBOINCGUIApp::OnInit() { iDesiredLanguageCode = pLI->Language; } } + +#ifdef __WXMAC__ + // wxLocale::Init(wxLANGUAGE_DEFAULT) does not work correctly + // on the Mac so we must use wxUILocale::GetSystemLanguage(). + if (m_bUseDefaultLocale || (iDesiredLanguageCode == wxLANGUAGE_DEFAULT)) { + iDesiredLanguageCode = wxUILocale::GetSystemLanguage(); + m_strISOLanguageCode = wxLocale::GetLanguageCanonicalName(iDesiredLanguageCode); + } +#endif + m_pLocale->Init(iDesiredLanguageCode); if (iDesiredLanguageCode == wxLANGUAGE_DEFAULT) { m_strISOLanguageCode = m_pLocale->GetCanonicalName();