mirror of
https://github.com/cookiengineer/audacity
synced 2025-07-03 06:03:13 +02:00
Move language setting and event from AudacityApp.h to GUIPrefs.h
This commit is contained in:
parent
236c8ed51e
commit
4a4f8ebe4e
@ -26,8 +26,6 @@ It handles initialization and termination by subclassing wxApp.
|
||||
#include <vld.h>
|
||||
#endif
|
||||
|
||||
#include "TranslatableStringArray.h"
|
||||
|
||||
#include <wx/setup.h> // for wxUSE_* macros
|
||||
#include <wx/wxcrtvararg.h>
|
||||
#include <wx/defs.h>
|
||||
@ -99,6 +97,7 @@ It handles initialization and termination by subclassing wxApp.
|
||||
#include "ondemand/ODManager.h"
|
||||
#include "widgets/ErrorDialog.h"
|
||||
#include "prefs/DirectoriesPrefs.h"
|
||||
#include "prefs/GUIPrefs.h"
|
||||
#include "tracks/ui/Scrubbing.h"
|
||||
#include "widgets/FileHistory.h"
|
||||
|
||||
@ -245,8 +244,6 @@ It handles initialization and termination by subclassing wxApp.
|
||||
/// Custom events
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
wxDEFINE_EVENT(EVT_LANGUAGE_CHANGE, wxCommandEvent);
|
||||
|
||||
#if 0
|
||||
#ifdef __WXGTK__
|
||||
static void wxOnAssert(const wxChar *fileName, int lineNumber, const wxChar *msg)
|
||||
@ -941,97 +938,6 @@ wxLanguageInfo userLangs[] =
|
||||
};
|
||||
#endif
|
||||
|
||||
wxString AudacityApp::InitLang( wxString langCode )
|
||||
{
|
||||
if ( langCode.empty() )
|
||||
langCode = gPrefs->Read(wxT("/Locale/Language"), wxEmptyString);
|
||||
|
||||
// Use the system default language if one wasn't specified or if the user selected System.
|
||||
if (langCode.empty())
|
||||
{
|
||||
langCode = GetSystemLanguageCode();
|
||||
}
|
||||
|
||||
// Initialize the language
|
||||
return SetLang(langCode);
|
||||
}
|
||||
|
||||
wxString AudacityApp::SetLang( const wxString & lang )
|
||||
{
|
||||
wxString result = lang;
|
||||
|
||||
mLocale.reset();
|
||||
|
||||
#if defined(__WXMAC__)
|
||||
// This should be reviewed again during the wx3 conversion.
|
||||
|
||||
// On OSX, if the LANG environment variable isn't set when
|
||||
// using a language like Japanese, an assertion will trigger
|
||||
// because conversion to Japanese from "?" doesn't return a
|
||||
// valid length, so make OSX happy by defining/overriding
|
||||
// the LANG environment variable with U.S. English for now.
|
||||
wxSetEnv(wxT("LANG"), wxT("en_US.UTF-8"));
|
||||
#endif
|
||||
|
||||
const wxLanguageInfo *info = NULL;
|
||||
if (!lang.empty()) {
|
||||
info = wxLocale::FindLanguageInfo(lang);
|
||||
if (!info)
|
||||
::AudacityMessageBox(wxString::Format(_("Language \"%s\" is unknown"), lang));
|
||||
}
|
||||
if (!info)
|
||||
{
|
||||
result = GetSystemLanguageCode();
|
||||
info = wxLocale::FindLanguageInfo(result);
|
||||
if (!info)
|
||||
return result;
|
||||
}
|
||||
mLocale = std::make_unique<wxLocale>(info->Language);
|
||||
|
||||
for( const auto &path : FileNames::AudacityPathList() )
|
||||
mLocale->AddCatalogLookupPathPrefix( path );
|
||||
|
||||
// LL: Must add the wxWidgets catalog manually since the search
|
||||
// paths were not set up when mLocale was created. The
|
||||
// catalogs are search in LIFO order, so add wxstd first.
|
||||
mLocale->AddCatalog(wxT("wxstd"));
|
||||
|
||||
// AUDACITY_NAME is legitimately used on some *nix configurations.
|
||||
#ifdef AUDACITY_NAME
|
||||
mLocale->AddCatalog(wxT(AUDACITY_NAME));
|
||||
#else
|
||||
mLocale->AddCatalog(IPC_APPL);
|
||||
#endif
|
||||
|
||||
// Initialize internationalisation (number formats etc.)
|
||||
//
|
||||
// This must go _after_ creating the wxLocale instance because
|
||||
// creating the wxLocale instance sets the application-wide locale.
|
||||
|
||||
Internat::Init();
|
||||
|
||||
// Notify listeners of language changes
|
||||
{
|
||||
wxCommandEvent evt(EVT_LANGUAGE_CHANGE);
|
||||
ProcessEvent(evt);
|
||||
}
|
||||
|
||||
// PRL: Moved this, do it only after language intialized
|
||||
// Unused strings that we want to be translated, even though
|
||||
// we're not using them yet...
|
||||
wxString future1 = _("Master Gain Control");
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
wxString AudacityApp::GetLang() const
|
||||
{
|
||||
if (mLocale)
|
||||
return mLocale->GetSysName();
|
||||
else
|
||||
return {};
|
||||
}
|
||||
|
||||
void AudacityApp::OnFatalException()
|
||||
{
|
||||
#if defined(EXPERIMENTAL_CRASH_REPORT)
|
||||
@ -1112,9 +1018,9 @@ void AudacityApp::GenerateCrashReport(wxDebugReport::Context ctx)
|
||||
|
||||
if (ctx == wxDebugReport::Context_Current)
|
||||
{
|
||||
auto saveLang = GetLang();
|
||||
InitLang( wxT("en") );
|
||||
auto cleanup = finally( [&]{ InitLang( saveLang ); } );
|
||||
auto saveLang = GUIPrefs::GetLang();
|
||||
GUIPrefs::InitLang( wxT("en") );
|
||||
auto cleanup = finally( [&]{ GUIPrefs::InitLang( saveLang ); } );
|
||||
|
||||
rpt.AddText(wxT("audiodev.txt"), gAudioIO->GetDeviceInfo(), wxT("Audio Device Info"));
|
||||
#ifdef EXPERIMENTAL_MIDI_OUT
|
||||
@ -1235,8 +1141,6 @@ bool AudacityApp::OnInit()
|
||||
std::unique_ptr < wxLog >
|
||||
{ wxLog::SetActiveTarget(safenew AudacityLogger) }; // DELETE old
|
||||
|
||||
mLocale = NULL;
|
||||
|
||||
#if defined(__WXMAC__)
|
||||
// Disable window animation
|
||||
wxSystemOptions::SetOption(wxMAC_WINDOW_PLAIN_TRANSITION, 1);
|
||||
|
@ -59,18 +59,6 @@ class AudacityApp final : public wxApp {
|
||||
|
||||
int FilterEvent(wxEvent & event) override;
|
||||
|
||||
// If no input language given, defaults first to choice in preferences, then
|
||||
// to system language.
|
||||
// Returns the language actually used which is not lang if lang cannot be found.
|
||||
wxString InitLang( wxString lang = {} );
|
||||
|
||||
// If no input language given, defaults to system language.
|
||||
// Returns the language actually used which is not lang if lang cannot be found.
|
||||
wxString SetLang( const wxString & lang );
|
||||
|
||||
// Returns the last language code that was set
|
||||
wxString GetLang() const;
|
||||
|
||||
// These are currently only used on Mac OS, where it's
|
||||
// possible to have a menu bar but no windows open. It doesn't
|
||||
// hurt any other platforms, though.
|
||||
@ -131,8 +119,6 @@ class AudacityApp final : public wxApp {
|
||||
private:
|
||||
std::unique_ptr<CommandHandler> mCmdHandler;
|
||||
|
||||
std::unique_ptr<wxLocale> mLocale;
|
||||
|
||||
std::unique_ptr<wxSingleInstanceChecker> mChecker;
|
||||
|
||||
wxTimer mTimer;
|
||||
|
@ -60,10 +60,10 @@
|
||||
#include <wx/filename.h>
|
||||
#include <wx/stdpaths.h>
|
||||
|
||||
#include "AudacityApp.h"
|
||||
#include "FileNames.h"
|
||||
#include "Languages.h"
|
||||
|
||||
#include "prefs/GUIPrefs.h"
|
||||
#include "widgets/ErrorDialog.h"
|
||||
|
||||
std::unique_ptr<AudacityPrefs> ugPrefs {};
|
||||
@ -216,7 +216,7 @@ void InitPreferences()
|
||||
}
|
||||
}
|
||||
|
||||
langCode = wxGetApp().InitLang( langCode );
|
||||
langCode = GUIPrefs::InitLang( langCode );
|
||||
|
||||
// User requested that the preferences be completely reset
|
||||
if (resetPrefs)
|
||||
|
@ -54,7 +54,6 @@ effects from this one class.
|
||||
#include <wx/stdpaths.h>
|
||||
|
||||
#include "../EffectManager.h"
|
||||
#include "../../AudacityApp.h"
|
||||
#include "../../DirManager.h"
|
||||
#include "../../FileNames.h"
|
||||
#include "../../LabelTrack.h"
|
||||
@ -70,6 +69,7 @@ effects from this one class.
|
||||
#include "../../widgets/ErrorDialog.h"
|
||||
#include "../../Prefs.h"
|
||||
#include "../../wxFileNameWrapper.h"
|
||||
#include "../../prefs/GUIPrefs.h"
|
||||
#include "../../prefs/WaveformSettings.h"
|
||||
#include "../../widgets/NumericTextCtrl.h"
|
||||
#include "../../widgets/ProgressDialog.h"
|
||||
@ -655,7 +655,7 @@ bool NyquistEffect::Process()
|
||||
|
||||
mProps += wxString::Format(wxT("(putprop '*AUDACITY* (list %d %d %d) 'VERSION)\n"), AUDACITY_VERSION, AUDACITY_RELEASE, AUDACITY_REVISION);
|
||||
wxString lang = gPrefs->Read(wxT("/Locale/Language"), wxT(""));
|
||||
lang = (lang.empty())? wxGetApp().SetLang(lang) : lang;
|
||||
lang = (lang.empty())? GUIPrefs::SetLang(lang) : lang;
|
||||
mProps += wxString::Format(wxT("(putprop '*AUDACITY* \"%s\" 'LANGUAGE)\n"), lang);
|
||||
|
||||
mProps += wxString::Format(wxT("(setf *DECIMAL-SEPARATOR* #\\%c)\n"), wxNumberFormatter::GetDecimalSeparator());
|
||||
|
@ -22,9 +22,10 @@
|
||||
|
||||
#include "../Experimental.h"
|
||||
|
||||
#include <wx/app.h>
|
||||
#include <wx/defs.h>
|
||||
|
||||
#include "../AudacityApp.h"
|
||||
#include "../FileNames.h"
|
||||
#include "../Languages.h"
|
||||
#include "../Theme.h"
|
||||
#include "../Prefs.h"
|
||||
@ -34,6 +35,10 @@
|
||||
|
||||
#include "ThemePrefs.h"
|
||||
#include "../AColor.h"
|
||||
#include "../TranslatableStringArray.h"
|
||||
#include "../widgets/ErrorDialog.h"
|
||||
|
||||
wxDEFINE_EVENT(EVT_LANGUAGE_CHANGE, wxCommandEvent);
|
||||
|
||||
GUIPrefs::GUIPrefs(wxWindow * parent, wxWindowID winid)
|
||||
/* i18n-hint: refers to Audacity's user interface settings */
|
||||
@ -256,7 +261,7 @@ bool GUIPrefs::Commit()
|
||||
|
||||
// If language has changed, we want to change it now, not on the next reboot.
|
||||
wxString lang = gPrefs->Read(wxT("/Locale/Language"), wxT(""));
|
||||
wxString usedLang = wxGetApp().SetLang(lang);
|
||||
wxString usedLang = SetLang(lang);
|
||||
// Bug 1523: Previously didn't check no-language (=System Language)
|
||||
if (!(lang.empty()) && (lang != usedLang)) {
|
||||
// lang was not usable and is not system language. We got overridden.
|
||||
@ -267,6 +272,99 @@ bool GUIPrefs::Commit()
|
||||
return true;
|
||||
}
|
||||
|
||||
wxString GUIPrefs::InitLang( wxString langCode )
|
||||
{
|
||||
if ( langCode.empty() )
|
||||
langCode = gPrefs->Read(wxT("/Locale/Language"), wxEmptyString);
|
||||
|
||||
// Use the system default language if one wasn't specified or if the user selected System.
|
||||
if (langCode.empty())
|
||||
{
|
||||
langCode = GetSystemLanguageCode();
|
||||
}
|
||||
|
||||
// Initialize the language
|
||||
return SetLang(langCode);
|
||||
}
|
||||
|
||||
static std::unique_ptr<wxLocale> sLocale;
|
||||
|
||||
wxString GUIPrefs::SetLang( const wxString & lang )
|
||||
{
|
||||
wxString result = lang;
|
||||
|
||||
sLocale.reset();
|
||||
|
||||
#if defined(__WXMAC__)
|
||||
// This should be reviewed again during the wx3 conversion.
|
||||
|
||||
// On OSX, if the LANG environment variable isn't set when
|
||||
// using a language like Japanese, an assertion will trigger
|
||||
// because conversion to Japanese from "?" doesn't return a
|
||||
// valid length, so make OSX happy by defining/overriding
|
||||
// the LANG environment variable with U.S. English for now.
|
||||
wxSetEnv(wxT("LANG"), wxT("en_US.UTF-8"));
|
||||
#endif
|
||||
|
||||
const wxLanguageInfo *info = NULL;
|
||||
if (!lang.empty()) {
|
||||
info = wxLocale::FindLanguageInfo(lang);
|
||||
if (!info)
|
||||
::AudacityMessageBox(wxString::Format(_("Language \"%s\" is unknown"), lang));
|
||||
}
|
||||
if (!info)
|
||||
{
|
||||
result = GetSystemLanguageCode();
|
||||
info = wxLocale::FindLanguageInfo(result);
|
||||
if (!info)
|
||||
return result;
|
||||
}
|
||||
sLocale = std::make_unique<wxLocale>(info->Language);
|
||||
|
||||
for( const auto &path : FileNames::AudacityPathList() )
|
||||
sLocale->AddCatalogLookupPathPrefix( path );
|
||||
|
||||
// LL: Must add the wxWidgets catalog manually since the search
|
||||
// paths were not set up when mLocale was created. The
|
||||
// catalogs are search in LIFO order, so add wxstd first.
|
||||
sLocale->AddCatalog(wxT("wxstd"));
|
||||
|
||||
// AUDACITY_NAME is legitimately used on some *nix configurations.
|
||||
#ifdef AUDACITY_NAME
|
||||
sLocale->AddCatalog(wxT(AUDACITY_NAME));
|
||||
#else
|
||||
sLocale->AddCatalog(IPC_APPL);
|
||||
#endif
|
||||
|
||||
// Initialize internationalisation (number formats etc.)
|
||||
//
|
||||
// This must go _after_ creating the wxLocale instance because
|
||||
// creating the wxLocale instance sets the application-wide locale.
|
||||
|
||||
Internat::Init();
|
||||
|
||||
// Notify listeners of language changes
|
||||
{
|
||||
wxCommandEvent evt(EVT_LANGUAGE_CHANGE);
|
||||
wxTheApp->ProcessEvent(evt);
|
||||
}
|
||||
|
||||
// PRL: Moved this, do it only after language intialized
|
||||
// Unused strings that we want to be translated, even though
|
||||
// we're not using them yet...
|
||||
wxString future1 = _("Master Gain Control");
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
wxString GUIPrefs::GetLang()
|
||||
{
|
||||
if (sLocale)
|
||||
return sLocale->GetSysName();
|
||||
else
|
||||
return {};
|
||||
}
|
||||
|
||||
PrefsPanel::Factory
|
||||
GUIPrefsFactory = [](wxWindow *parent, wxWindowID winid)
|
||||
{
|
||||
|
@ -37,6 +37,18 @@ class GUIPrefs final : public PrefsPanel
|
||||
static void GetRangeChoices(
|
||||
wxArrayStringEx *pChoices, wxArrayStringEx *pCodes);
|
||||
|
||||
// If no input language given, defaults first to choice in preferences, then
|
||||
// to system language.
|
||||
// Returns the language actually used which is not lang if lang cannot be found.
|
||||
static wxString InitLang( wxString lang = {} );
|
||||
|
||||
// If no input language given, defaults to system language.
|
||||
// Returns the language actually used which is not lang if lang cannot be found.
|
||||
static wxString SetLang( const wxString & lang );
|
||||
|
||||
// Returns the last language code that was set
|
||||
static wxString GetLang();
|
||||
|
||||
private:
|
||||
void Populate();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user