mirror of
https://github.com/cookiengineer/audacity
synced 2025-06-17 00:20:06 +02:00
Define and use TranslatableStringArray. This lets you define "listeners"...
... for language changes, without inserting extra code to send the notifications.
This commit is contained in:
parent
5c77d34a35
commit
b9db3bd83d
@ -22,6 +22,7 @@ It handles initialization and termination by subclassing wxApp.
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "Audacity.h" // This should always be included first
|
#include "Audacity.h" // This should always be included first
|
||||||
|
#include "TranslatableStringArray.h"
|
||||||
|
|
||||||
#include <wx/defs.h>
|
#include <wx/defs.h>
|
||||||
#include <wx/app.h>
|
#include <wx/app.h>
|
||||||
@ -93,8 +94,6 @@ It handles initialization and termination by subclassing wxApp.
|
|||||||
#include "commands/Keyboard.h"
|
#include "commands/Keyboard.h"
|
||||||
#include "widgets/ErrorDialog.h"
|
#include "widgets/ErrorDialog.h"
|
||||||
#include "prefs/DirectoriesPrefs.h"
|
#include "prefs/DirectoriesPrefs.h"
|
||||||
#include "prefs/SpectrogramSettings.h"
|
|
||||||
#include "prefs/WaveformSettings.h"
|
|
||||||
|
|
||||||
//temporarilly commented out till it is added to all projects
|
//temporarilly commented out till it is added to all projects
|
||||||
//#include "Profiler.h"
|
//#include "Profiler.h"
|
||||||
@ -234,6 +233,7 @@ It handles initialization and termination by subclassing wxApp.
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
DEFINE_EVENT_TYPE(EVT_OPEN_AUDIO_FILE);
|
DEFINE_EVENT_TYPE(EVT_OPEN_AUDIO_FILE);
|
||||||
|
DEFINE_EVENT_TYPE(EVT_LANGUAGE_CHANGE);
|
||||||
|
|
||||||
#ifdef __WXGTK__
|
#ifdef __WXGTK__
|
||||||
static void wxOnAssert(const wxChar *fileName, int lineNumber, const wxChar *msg)
|
static void wxOnAssert(const wxChar *fileName, int lineNumber, const wxChar *msg)
|
||||||
@ -1039,9 +1039,11 @@ void AudacityApp::InitLang( const wxString & lang )
|
|||||||
|
|
||||||
Internat::Init();
|
Internat::Init();
|
||||||
|
|
||||||
// Some static arrays unconnected with any project want to be informed of language changes.
|
// Notify listeners of language changes
|
||||||
SpectrogramSettings::InvalidateNames();
|
{
|
||||||
WaveformSettings::InvalidateNames();
|
wxCommandEvent evt(EVT_LANGUAGE_CHANGE);
|
||||||
|
ProcessEvent(evt);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AudacityApp::OnFatalException()
|
void AudacityApp::OnFatalException()
|
||||||
|
@ -231,6 +231,7 @@ audacity_SOURCES = \
|
|||||||
TrackPanel.h \
|
TrackPanel.h \
|
||||||
TrackPanelAx.cpp \
|
TrackPanelAx.cpp \
|
||||||
TrackPanelAx.h \
|
TrackPanelAx.h \
|
||||||
|
TranslatableStringArray.h \
|
||||||
UndoManager.cpp \
|
UndoManager.cpp \
|
||||||
UndoManager.h \
|
UndoManager.h \
|
||||||
ViewInfo.cpp \
|
ViewInfo.cpp \
|
||||||
|
80
src/TranslatableStringArray.h
Normal file
80
src/TranslatableStringArray.h
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
/**********************************************************************
|
||||||
|
|
||||||
|
Audacity: A Digital Audio Editor
|
||||||
|
|
||||||
|
TranslatableStringArray.h
|
||||||
|
|
||||||
|
Paul Licameli
|
||||||
|
|
||||||
|
**********************************************************************/
|
||||||
|
|
||||||
|
#ifndef __AUDACITY_TRANSLATABLE_STRING_ARRAY__
|
||||||
|
#define __AUDACITY_TRANSLATABLE_STRING_ARRAY__
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <wx/app.h>
|
||||||
|
#include <wx/event.h>
|
||||||
|
|
||||||
|
class wxArrayString;
|
||||||
|
|
||||||
|
DECLARE_EXPORTED_EVENT_TYPE(AUDACITY_DLL_API, EVT_LANGUAGE_CHANGE, -1);
|
||||||
|
|
||||||
|
/*
|
||||||
|
This class can maintain a static table containing user visible strings that updates
|
||||||
|
itself properly when the language is changed in Preferences.
|
||||||
|
|
||||||
|
Typical usage is to define a derived class, override Populate(), and then
|
||||||
|
make a singleton instance of the class.
|
||||||
|
|
||||||
|
Populate() is called only as needed to fill the table on demand the first
|
||||||
|
time it is used after application startup or language change.
|
||||||
|
*/
|
||||||
|
|
||||||
|
template<typename ArrayType> class TranslatableArray
|
||||||
|
: public wxEvtHandler
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
TranslatableArray()
|
||||||
|
{
|
||||||
|
if (wxTheApp)
|
||||||
|
wxTheApp->Connect(EVT_LANGUAGE_CHANGE,
|
||||||
|
wxCommandEventHandler(TranslatableArray::Invalidate),
|
||||||
|
NULL,
|
||||||
|
this);
|
||||||
|
}
|
||||||
|
|
||||||
|
~TranslatableArray()
|
||||||
|
{
|
||||||
|
if (wxTheApp)
|
||||||
|
wxTheApp->Disconnect(EVT_LANGUAGE_CHANGE,
|
||||||
|
wxCommandEventHandler(TranslatableArray::Invalidate),
|
||||||
|
NULL,
|
||||||
|
this);
|
||||||
|
}
|
||||||
|
|
||||||
|
const ArrayType& Get()
|
||||||
|
{
|
||||||
|
if (mContents.empty())
|
||||||
|
Populate();
|
||||||
|
return mContents;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// Override this function to fill in mContents,
|
||||||
|
// typically by lines like
|
||||||
|
// mContents.push_back(_("Translate me"));
|
||||||
|
virtual void Populate() = 0;
|
||||||
|
|
||||||
|
void Invalidate(wxCommandEvent &evt)
|
||||||
|
{
|
||||||
|
mContents.clear();
|
||||||
|
evt.Skip();
|
||||||
|
}
|
||||||
|
|
||||||
|
ArrayType mContents;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef TranslatableArray<wxArrayString> TranslatableStringArray;
|
||||||
|
|
||||||
|
#endif
|
@ -16,6 +16,7 @@ Paul Licameli
|
|||||||
#include "../Audacity.h"
|
#include "../Audacity.h"
|
||||||
#include "SpectrogramSettings.h"
|
#include "SpectrogramSettings.h"
|
||||||
#include "../NumberScale.h"
|
#include "../NumberScale.h"
|
||||||
|
#include "../TranslatableStringArray.h"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <wx/msgdlg.h>
|
#include <wx/msgdlg.h>
|
||||||
@ -142,65 +143,49 @@ SpectrogramSettings& SpectrogramSettings::defaults()
|
|||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
|
||||||
{
|
|
||||||
wxArrayString &scaleNamesArray()
|
|
||||||
{
|
|
||||||
static wxArrayString theArray;
|
|
||||||
return theArray;
|
|
||||||
}
|
|
||||||
|
|
||||||
wxArrayString &algorithmNamesArray()
|
|
||||||
{
|
|
||||||
static wxArrayString theArray;
|
|
||||||
return theArray;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//static
|
|
||||||
void SpectrogramSettings::InvalidateNames()
|
|
||||||
{
|
|
||||||
scaleNamesArray().Clear();
|
|
||||||
algorithmNamesArray().Clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
//static
|
//static
|
||||||
const wxArrayString &SpectrogramSettings::GetScaleNames()
|
const wxArrayString &SpectrogramSettings::GetScaleNames()
|
||||||
{
|
{
|
||||||
wxArrayString &theArray = scaleNamesArray();
|
class ScaleNamesArray : public TranslatableStringArray
|
||||||
|
{
|
||||||
|
virtual void Populate()
|
||||||
|
{
|
||||||
|
// Keep in correspondence with enum SpectrogramSettings::ScaleType:
|
||||||
|
mContents.Add(_("Linear"));
|
||||||
|
mContents.Add(_("Logarithmic"));
|
||||||
|
/* i18n-hint: The name of a frequency scale in psychoacoustics */
|
||||||
|
mContents.Add(_("Mel"));
|
||||||
|
/* i18n-hint: The name of a frequency scale in psychoacoustics, named for Heinrich Barkhausen */
|
||||||
|
mContents.Add(_("Bark"));
|
||||||
|
/* i18n-hint: The name of a frequency scale in psychoacoustics, abbreviates Equivalent Rectangular Bandwidth */
|
||||||
|
mContents.Add(_("ERBS"));
|
||||||
|
/* i18n-hint: A mathematical formula where f stands for frequency */
|
||||||
|
mContents.Add(_("1 / f"));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
if (theArray.IsEmpty()) {
|
static ScaleNamesArray theArray;
|
||||||
// Keep in correspondence with enum SpectrogramSettings::ScaleType:
|
return theArray.Get();
|
||||||
theArray.Add(_("Linear"));
|
|
||||||
theArray.Add(_("Logarithmic"));
|
|
||||||
/* i18n-hint: The name of a frequency scale in psychoacoustics */
|
|
||||||
theArray.Add(_("Mel"));
|
|
||||||
/* i18n-hint: The name of a frequency scale in psychoacoustics, named for Heinrich Barkhausen */
|
|
||||||
theArray.Add(_("Bark"));
|
|
||||||
/* i18n-hint: The name of a frequency scale in psychoacoustics, abbreviates Equivalent Rectangular Bandwidth */
|
|
||||||
theArray.Add(_("ERBS"));
|
|
||||||
/* i18n-hint: A mathematical formula where f stands for frequency */
|
|
||||||
theArray.Add(_("1 / f"));
|
|
||||||
}
|
|
||||||
|
|
||||||
return theArray;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//static
|
//static
|
||||||
const wxArrayString &SpectrogramSettings::GetAlgorithmNames()
|
const wxArrayString &SpectrogramSettings::GetAlgorithmNames()
|
||||||
{
|
{
|
||||||
wxArrayString &theArray = algorithmNamesArray();
|
class AlgorithmNamesArray : public TranslatableStringArray
|
||||||
|
{
|
||||||
|
virtual void Populate()
|
||||||
|
{
|
||||||
|
// Keep in correspondence with enum SpectrogramSettings::Algorithm:
|
||||||
|
mContents.Add(_("Frequencies"));
|
||||||
|
/* i18n-hint: the Reassignment algorithm for spectrograms */
|
||||||
|
mContents.Add(_("Reassignment"));
|
||||||
|
/* i18n-hint: EAC abbreviates "Enhanced Autocorrelation" */
|
||||||
|
mContents.Add(_("Pitch (EAC)"));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
if (theArray.IsEmpty()) {
|
static AlgorithmNamesArray theArray;
|
||||||
// Keep in correspondence with enum SpectrogramSettings::Algorithm:
|
return theArray.Get();
|
||||||
theArray.Add(_("Frequencies"));
|
|
||||||
/* i18n-hint: the Reassignment algorithm for spectrograms */
|
|
||||||
theArray.Add(_("Reassignment"));
|
|
||||||
/* i18n-hint: EAC abbreviates "Enhanced Autocorrelation" */
|
|
||||||
theArray.Add(_("Pitch (EAC)"));
|
|
||||||
}
|
|
||||||
|
|
||||||
return theArray;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SpectrogramSettings::Validate(bool quiet)
|
bool SpectrogramSettings::Validate(bool quiet)
|
||||||
|
@ -62,7 +62,6 @@ public:
|
|||||||
stNumScaleTypes,
|
stNumScaleTypes,
|
||||||
};
|
};
|
||||||
|
|
||||||
static void InvalidateNames(); // in case of language change
|
|
||||||
static const wxArrayString &GetScaleNames();
|
static const wxArrayString &GetScaleNames();
|
||||||
static const wxArrayString &GetAlgorithmNames();
|
static const wxArrayString &GetAlgorithmNames();
|
||||||
|
|
||||||
|
@ -22,6 +22,7 @@ Paul Licameli
|
|||||||
#include <wx/intl.h>
|
#include <wx/intl.h>
|
||||||
|
|
||||||
#include "../Prefs.h"
|
#include "../Prefs.h"
|
||||||
|
#include "../TranslatableStringArray.h"
|
||||||
|
|
||||||
WaveformSettings::Globals::Globals()
|
WaveformSettings::Globals::Globals()
|
||||||
{
|
{
|
||||||
@ -145,33 +146,21 @@ void WaveformSettings::NextHigherDBRange()
|
|||||||
ConvertToActualDBRange();
|
ConvertToActualDBRange();
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
|
||||||
{
|
|
||||||
wxArrayString &scaleNamesArray()
|
|
||||||
{
|
|
||||||
static wxArrayString theArray;
|
|
||||||
return theArray;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//static
|
|
||||||
void WaveformSettings::InvalidateNames()
|
|
||||||
{
|
|
||||||
scaleNamesArray().Clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
//static
|
//static
|
||||||
const wxArrayString &WaveformSettings::GetScaleNames()
|
const wxArrayString &WaveformSettings::GetScaleNames()
|
||||||
{
|
{
|
||||||
wxArrayString &theArray = scaleNamesArray();
|
class ScaleNamesArray : public TranslatableStringArray
|
||||||
|
{
|
||||||
|
virtual void Populate()
|
||||||
|
{
|
||||||
|
// Keep in correspondence with enum WaveTrack::WaveTrackDisplay:
|
||||||
|
mContents.Add(_("Linear"));
|
||||||
|
mContents.Add(_("Logarithmic"));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
if (theArray.IsEmpty()) {
|
static ScaleNamesArray theArray;
|
||||||
// Keep in correspondence with enum WaveTrack::WaveTrackDisplay:
|
return theArray.Get();
|
||||||
theArray.Add(_("Linear"));
|
|
||||||
theArray.Add(_("Logarithmic"));
|
|
||||||
}
|
|
||||||
|
|
||||||
return theArray;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
WaveformSettings::~WaveformSettings()
|
WaveformSettings::~WaveformSettings()
|
||||||
|
@ -57,7 +57,6 @@ public:
|
|||||||
stNumScaleTypes,
|
stNumScaleTypes,
|
||||||
};
|
};
|
||||||
|
|
||||||
static void InvalidateNames(); // in case of language change
|
|
||||||
static const wxArrayString &GetScaleNames();
|
static const wxArrayString &GetScaleNames();
|
||||||
|
|
||||||
ScaleType scaleType;
|
ScaleType scaleType;
|
||||||
|
@ -434,6 +434,7 @@
|
|||||||
<ClInclude Include="..\..\..\src\SseMathFuncs.h" />
|
<ClInclude Include="..\..\..\src\SseMathFuncs.h" />
|
||||||
<ClInclude Include="..\..\..\src\toolbars\SpectralSelectionBar.h" />
|
<ClInclude Include="..\..\..\src\toolbars\SpectralSelectionBar.h" />
|
||||||
<ClInclude Include="..\..\..\src\toolbars\SpectralSelectionBarListener.h" />
|
<ClInclude Include="..\..\..\src\toolbars\SpectralSelectionBarListener.h" />
|
||||||
|
<ClInclude Include="..\..\..\src\TranslatableStringArray.h" />
|
||||||
<ClInclude Include="..\..\..\src\WaveTrackLocation.h" />
|
<ClInclude Include="..\..\..\src\WaveTrackLocation.h" />
|
||||||
<ClInclude Include="..\..\..\src\widgets\HelpSystem.h" />
|
<ClInclude Include="..\..\..\src\widgets\HelpSystem.h" />
|
||||||
<ClInclude Include="..\..\..\src\widgets\NumericTextCtrl.h" />
|
<ClInclude Include="..\..\..\src\widgets\NumericTextCtrl.h" />
|
||||||
|
@ -1708,6 +1708,9 @@
|
|||||||
<ClInclude Include="..\..\..\src\effects\VST\VSTControlMSW.h">
|
<ClInclude Include="..\..\..\src\effects\VST\VSTControlMSW.h">
|
||||||
<Filter>src\effects\VST</Filter>
|
<Filter>src\effects\VST</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\..\src\TranslatableStringArray.h">
|
||||||
|
<Filter>src</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Image Include="..\..\audacity.ico">
|
<Image Include="..\..\audacity.ico">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user