1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-10-24 15:23:52 +02:00

Bug1288: Don't crash when changing language to "Simplified"...

... but give a warning message about the unknown language.
This commit is contained in:
Paul Licameli
2016-01-26 20:09:54 -05:00
parent 2550a59c0e
commit 907c950a0e
4 changed files with 25 additions and 9 deletions

View File

@@ -985,8 +985,10 @@ wxLanguageInfo userLangs[] =
}; };
#endif #endif
void AudacityApp::InitLang( const wxString & lang ) wxString AudacityApp::InitLang( const wxString & lang )
{ {
wxString result = lang;
if (mLocale) if (mLocale)
delete mLocale; delete mLocale;
@@ -1001,10 +1003,18 @@ void AudacityApp::InitLang( const wxString & lang )
wxSetEnv(wxT("LANG"), wxT("en_US.UTF-8")); wxSetEnv(wxT("LANG"), wxT("en_US.UTF-8"));
#endif #endif
const wxLanguageInfo *info = wxLocale::FindLanguageInfo(lang); const wxLanguageInfo *info = NULL;
if (!lang) 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); mLocale = new wxLocale(info->Language);
@@ -1035,6 +1045,8 @@ void AudacityApp::InitLang( const wxString & lang )
wxCommandEvent evt(EVT_LANGUAGE_CHANGE); wxCommandEvent evt(EVT_LANGUAGE_CHANGE);
ProcessEvent(evt); ProcessEvent(evt);
} }
return result;
} }
void AudacityApp::OnFatalException() void AudacityApp::OnFatalException()

View File

@@ -105,7 +105,8 @@ class AudacityApp:public wxApp {
int FilterEvent(wxEvent & event); 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 // These are currently only used on Mac OS, where it's
// possible to have a menu bar but no windows open. It doesn't // possible to have a menu bar but no windows open. It doesn't

View File

@@ -182,7 +182,7 @@ void InitPreferences()
} }
// Initialize the language // Initialize the language
wxGetApp().InitLang(langCode); langCode = wxGetApp().InitLang(langCode);
// User requested that the preferences be completely reset // User requested that the preferences be completely reset
if (resetPrefs) if (resetPrefs)

View File

@@ -166,9 +166,12 @@ bool GUIPrefs::Apply()
// If language has changed, we want to change it now, not on the next reboot. // If language has changed, we want to change it now, not on the next reboot.
wxString lang = gPrefs->Read(wxT("/Locale/Language"), wxT("")); wxString lang = gPrefs->Read(wxT("/Locale/Language"), wxT(""));
if (lang == wxT("")) wxString usedLang = wxGetApp().InitLang(lang);
lang = GetSystemLanguageCode(); if (lang != usedLang) {
wxGetApp().InitLang(lang); // lang was not usable. We got overridden.
gPrefs->Write(wxT("/Locale/Language"), usedLang);
gPrefs->Flush();
}
return true; return true;
} }