From 907c950a0e20a59843f10615291cebb012d7007d Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Tue, 26 Jan 2016 20:09:54 -0500 Subject: [PATCH] Bug1288: Don't crash when changing language to "Simplified"... ... but give a warning message about the unknown language. --- src/AudacityApp.cpp | 20 ++++++++++++++++---- src/AudacityApp.h | 3 ++- src/Prefs.cpp | 2 +- src/prefs/GUIPrefs.cpp | 9 ++++++--- 4 files changed, 25 insertions(+), 9 deletions(-) diff --git a/src/AudacityApp.cpp b/src/AudacityApp.cpp index 7b6e4d01f..037eba642 100644 --- a/src/AudacityApp.cpp +++ b/src/AudacityApp.cpp @@ -985,8 +985,10 @@ wxLanguageInfo userLangs[] = }; #endif -void AudacityApp::InitLang( const wxString & lang ) +wxString AudacityApp::InitLang( const wxString & lang ) { + wxString result = lang; + if (mLocale) delete mLocale; @@ -1001,10 +1003,18 @@ void AudacityApp::InitLang( const wxString & lang ) wxSetEnv(wxT("LANG"), wxT("en_US.UTF-8")); #endif - const wxLanguageInfo *info = wxLocale::FindLanguageInfo(lang); - if (!lang) + const wxLanguageInfo *info = NULL; + if (!lang.empty()) { + info = wxLocale::FindLanguageInfo(lang); + if (!info) + ::wxMessageBox(wxString::Format(_("Language \"%s\" is unknown"), lang)); + } + if (!info) { - return; + result = GetSystemLanguageCode(); + info = wxLocale::FindLanguageInfo(result); + if (!info) + return result; } mLocale = new wxLocale(info->Language); @@ -1035,6 +1045,8 @@ void AudacityApp::InitLang( const wxString & lang ) wxCommandEvent evt(EVT_LANGUAGE_CHANGE); ProcessEvent(evt); } + + return result; } void AudacityApp::OnFatalException() diff --git a/src/AudacityApp.h b/src/AudacityApp.h index 3c360b3ec..9abc0b5a5 100644 --- a/src/AudacityApp.h +++ b/src/AudacityApp.h @@ -105,7 +105,8 @@ class AudacityApp:public wxApp { int FilterEvent(wxEvent & event); - void InitLang( const wxString & lang ); + // Returns the language actually used which is not lang if lang cannot be found. + wxString InitLang( const wxString & lang ); // These are currently only used on Mac OS, where it's // possible to have a menu bar but no windows open. It doesn't diff --git a/src/Prefs.cpp b/src/Prefs.cpp index cde37c2c3..c5360b937 100755 --- a/src/Prefs.cpp +++ b/src/Prefs.cpp @@ -182,7 +182,7 @@ void InitPreferences() } // Initialize the language - wxGetApp().InitLang(langCode); + langCode = wxGetApp().InitLang(langCode); // User requested that the preferences be completely reset if (resetPrefs) diff --git a/src/prefs/GUIPrefs.cpp b/src/prefs/GUIPrefs.cpp index 9842b7c7b..b0e4656a0 100644 --- a/src/prefs/GUIPrefs.cpp +++ b/src/prefs/GUIPrefs.cpp @@ -166,9 +166,12 @@ bool GUIPrefs::Apply() // If language has changed, we want to change it now, not on the next reboot. wxString lang = gPrefs->Read(wxT("/Locale/Language"), wxT("")); - if (lang == wxT("")) - lang = GetSystemLanguageCode(); - wxGetApp().InitLang(lang); + wxString usedLang = wxGetApp().InitLang(lang); + if (lang != usedLang) { + // lang was not usable. We got overridden. + gPrefs->Write(wxT("/Locale/Language"), usedLang); + gPrefs->Flush(); + } return true; }