1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-08-02 08:59:28 +02:00

TranslatableString caption & message in MessageBoxException

This commit is contained in:
Paul Licameli 2019-12-07 10:04:35 -05:00
parent 54e2bbd8ff
commit 503ccabdd8
16 changed files with 50 additions and 53 deletions

View File

@ -32,7 +32,7 @@ AudacityException::~AudacityException()
wxAtomicInt sOutstandingMessages {}; wxAtomicInt sOutstandingMessages {};
MessageBoxException::MessageBoxException( const wxString &caption_ ) MessageBoxException::MessageBoxException( const TranslatableString &caption_ )
: caption{ caption_ } : caption{ caption_ }
{ {
if (!caption.empty()) if (!caption.empty())
@ -80,7 +80,7 @@ SimpleMessageBoxException::~SimpleMessageBoxException()
{ {
} }
wxString SimpleMessageBoxException::ErrorMessage() const TranslatableString SimpleMessageBoxException::ErrorMessage() const
{ {
return message; return message;
} }
@ -96,8 +96,8 @@ void MessageBoxException::DelayedHandlerAction()
// give the user no useful added information. // give the user no useful added information.
if ( wxAtomicDec( sOutstandingMessages ) == 0 ) if ( wxAtomicDec( sOutstandingMessages ) == 0 )
::AudacityMessageBox( ::AudacityMessageBox(
ErrorMessage(), ErrorMessage().Translation(),
caption.empty() ? AudacityMessageBoxCaptionStr() : caption, (caption.empty() ? AudacityMessageBoxCaptionStr() : caption).Translation(),
wxICON_ERROR wxICON_ERROR
); );
moved = true; moved = true;

View File

@ -54,17 +54,17 @@ class MessageBoxException /* not final */ : public AudacityException
protected: protected:
// If default-constructed with empty caption, it makes no message box. // If default-constructed with empty caption, it makes no message box.
explicit MessageBoxException( const wxString &caption = wxString{} ); explicit MessageBoxException( const TranslatableString &caption = {} );
~MessageBoxException() override; ~MessageBoxException() override;
MessageBoxException( const MessageBoxException& ); MessageBoxException( const MessageBoxException& );
MessageBoxException &operator = ( MessageBoxException && ); MessageBoxException &operator = ( MessageBoxException && );
// Format a default, internationalized error message for this exception. // Format a default error message for this exception.
virtual wxString ErrorMessage() const = 0; virtual TranslatableString ErrorMessage() const = 0;
private: private:
wxString caption; TranslatableString caption;
mutable bool moved { false }; mutable bool moved { false };
}; };
@ -72,8 +72,8 @@ private:
class SimpleMessageBoxException /* not final */ : public MessageBoxException class SimpleMessageBoxException /* not final */ : public MessageBoxException
{ {
public: public:
explicit SimpleMessageBoxException( const wxString &message_, explicit SimpleMessageBoxException( const TranslatableString &message_,
const wxString &caption = _("Message") ) const TranslatableString &caption = XO("Message") )
: MessageBoxException{ caption } : MessageBoxException{ caption }
, message{ message_ } , message{ message_ }
{} {}
@ -84,10 +84,10 @@ public:
SimpleMessageBoxException && ) PROHIBITED; SimpleMessageBoxException && ) PROHIBITED;
// Format a default, internationalized error message for this exception. // Format a default, internationalized error message for this exception.
virtual wxString ErrorMessage() const override; virtual TranslatableString ErrorMessage() const override;
private: private:
wxString message; TranslatableString message;
}; };

View File

@ -15,24 +15,24 @@ FileException::~FileException()
{ {
} }
wxString FileException::ErrorMessage() const TranslatableString FileException::ErrorMessage() const
{ {
wxString format; TranslatableString format;
switch (cause) { switch (cause) {
case Cause::Open: case Cause::Open:
format = _("Audacity failed to open a file in %s."); format = XO("Audacity failed to open a file in %s.");
break; break;
case Cause::Read: case Cause::Read:
format = _("Audacity failed to read from a file in %s."); format = XO("Audacity failed to read from a file in %s.");
break; break;
case Cause::Write: case Cause::Write:
format = format =
_("Audacity failed to write to a file.\n" XO("Audacity failed to write to a file.\n"
"Perhaps %s is not writable or the disk is full."); "Perhaps %s is not writable or the disk is full.");
break; break;
case Cause::Rename: case Cause::Rename:
format = format =
_("Audacity successfully wrote a file in %s but failed to rename it as %s."); XO("Audacity successfully wrote a file in %s but failed to rename it as %s.");
default: default:
break; break;
} }
@ -54,7 +54,6 @@ _("Audacity successfully wrote a file in %s but failed to rename it as %s.");
#endif #endif
return wxString::Format( return format.Format( target, renameTarget.GetFullName() );
format, target, renameTarget.GetFullName() );
} }

View File

@ -19,7 +19,7 @@ public:
explicit FileException explicit FileException
( Cause cause_, const wxFileName &fileName_, ( Cause cause_, const wxFileName &fileName_,
const wxString &caption = _("File Error"), const TranslatableString &caption = XO("File Error"),
const wxFileName &renameTarget_ = {}) const wxFileName &renameTarget_ = {})
: MessageBoxException{ caption } : MessageBoxException{ caption }
, cause{ cause_ }, fileName{ fileName_ }, renameTarget{ renameTarget_ } , cause{ cause_ }, fileName{ fileName_ }, renameTarget{ renameTarget_ }
@ -38,7 +38,7 @@ public:
protected: protected:
// Format a default, internationalized error message for this exception. // Format a default, internationalized error message for this exception.
wxString ErrorMessage() const override; TranslatableString ErrorMessage() const override;
public: public:
Cause cause; Cause cause;

View File

@ -13,7 +13,7 @@ InconsistencyException::~InconsistencyException()
{ {
} }
wxString InconsistencyException::ErrorMessage() const TranslatableString InconsistencyException::ErrorMessage() const
{ {
// Shorten the path // Shorten the path
wxString path { file }; wxString path { file };
@ -23,14 +23,12 @@ wxString InconsistencyException::ErrorMessage() const
path = path.Mid(index + sub.size()); path = path.Mid(index + sub.size());
#ifdef __func__ #ifdef __func__
return wxString::Format( return
_("Internal error in %s at %s line %d.\nPlease inform the Audacity team at https://forum.audacityteam.org/."), XO("Internal error in %s at %s line %d.\nPlease inform the Audacity team at https://forum.audacityteam.org/.")
func, path, line .Format( func, path, line );
);
#else #else
return wxString::Format( return
_("Internal error at %s line %d.\nPlease inform the Audacity team at https://forum.audacityteam.org/."), XO("Internal error at %s line %d.\nPlease inform the Audacity team at https://forum.audacityteam.org/.")
path, line .Format( path, line );
);
#endif #endif
} }

View File

@ -22,7 +22,7 @@ public:
explicit InconsistencyException explicit InconsistencyException
( const char *fn, const char *f, unsigned l ) ( const char *fn, const char *f, unsigned l )
: MessageBoxException{ _("Internal Error") } : MessageBoxException{ XO("Internal Error") }
, func { fn }, file { f }, line { l } , func { fn }, file { f }, line { l }
{} {}
@ -49,7 +49,7 @@ public:
private: private:
// Format a default, internationalized error message for this exception. // Format a default, internationalized error message for this exception.
wxString ErrorMessage() const override; TranslatableString ErrorMessage() const override;
const char *func {}; const char *func {};
const char *file {}; const char *file {};

View File

@ -1159,7 +1159,7 @@ void ThemeBase::SaveComponents()
wxString::Format( wxString::Format(
_("Some required files in:\n %s\nwere already present. Overwrite?"), _("Some required files in:\n %s\nwere already present. Overwrite?"),
FileNames::ThemeComponentsDir()), FileNames::ThemeComponentsDir()),
AudacityMessageBoxCaptionStr(), AudacityMessageBoxCaptionStr().Translation(),
wxYES_NO | wxNO_DEFAULT); wxYES_NO | wxNO_DEFAULT);
if(result == wxNO) if(result == wxNO)
return; return;

View File

@ -1952,7 +1952,7 @@ void WaveClip::Resample(int rate, ProgressDialog *progress)
if (error) if (error)
throw SimpleMessageBoxException{ throw SimpleMessageBoxException{
_("Resampling failed.") XO("Resampling failed.")
}; };
else else
{ {

View File

@ -1228,7 +1228,7 @@ void WaveTrack::Paste(double t0, const Track *src)
// STRONG-GUARANTEE in case of this path // STRONG-GUARANTEE in case of this path
// not that it matters. // not that it matters.
throw SimpleMessageBoxException{ throw SimpleMessageBoxException{
_("There is not enough room available to paste the selection") XO("There is not enough room available to paste the selection")
}; };
} }
} }
@ -1248,7 +1248,7 @@ void WaveTrack::Paste(double t0, const Track *src)
// STRONG-GUARANTEE in case of this path // STRONG-GUARANTEE in case of this path
// not that it matters. // not that it matters.
throw SimpleMessageBoxException{ throw SimpleMessageBoxException{
_("There is not enough room available to paste the selection") XO("There is not enough room available to paste the selection")
}; };
for (const auto &clip : other->mClips) for (const auto &clip : other->mClips)
@ -2381,7 +2381,7 @@ void WaveTrack::ExpandCutLine(double cutLinePosition, double* cutlineStart,
clip->GetEndTime() + end - start > clip2->GetStartTime()) clip->GetEndTime() + end - start > clip2->GetStartTime())
// STRONG-GUARANTEE in case of this path // STRONG-GUARANTEE in case of this path
throw SimpleMessageBoxException{ throw SimpleMessageBoxException{
_("There is not enough room available to expand the cut line") XO("There is not enough room available to expand the cut line")
}; };
} }
} }

View File

@ -13,10 +13,9 @@ NotYetAvailableException::~NotYetAvailableException()
{ {
} }
wxString NotYetAvailableException::ErrorMessage() const TranslatableString NotYetAvailableException::ErrorMessage() const
{ {
return wxString::Format( return
_("This operation cannot be done until importation of %s completes."), XO("This operation cannot be done until importation of %s completes.")
fileName.GetFullName() .Format( fileName.GetFullName() );
);
} }

View File

@ -24,7 +24,7 @@ public:
~NotYetAvailableException(); ~NotYetAvailableException();
protected: protected:
wxString ErrorMessage() const override; TranslatableString ErrorMessage() const override;
}; };
#endif #endif

View File

@ -209,7 +209,7 @@ static void Extract(bool bits16,
} }
if( dataSizeIn < 1 ) if( dataSizeIn < 1 )
throw SimpleMessageBoxException{_("Bad data size")}; throw SimpleMessageBoxException{XO("Bad data size")};
size_t dataSize = (size_t)dataSizeIn; size_t dataSize = (size_t)dataSizeIn;

View File

@ -468,7 +468,7 @@ void OnPaste(const CommandContext &context)
// Throw, so that any previous changes to the project in this loop // Throw, so that any previous changes to the project in this loop
// are discarded. // are discarded.
throw SimpleMessageBoxException{ throw SimpleMessageBoxException{
_("Pasting one type of track into another is not allowed.") XO("Pasting one type of track into another is not allowed.")
}; };
// We should need this check only each time we visit the leading // We should need this check only each time we visit the leading
@ -496,7 +496,7 @@ void OnPaste(const CommandContext &context)
// Throw, so that any previous changes to the project in this // Throw, so that any previous changes to the project in this
// loop are discarded. // loop are discarded.
throw SimpleMessageBoxException{ throw SimpleMessageBoxException{
_("Copying stereo audio into a mono track is not allowed.") XO("Copying stereo audio into a mono track is not allowed.")
}; };
} }
} }

View File

@ -11,7 +11,7 @@
#include "AudacityMessageBox.h" #include "AudacityMessageBox.h"
#include "../Internat.h" #include "../Internat.h"
wxString AudacityMessageBoxCaptionStr() TranslatableString AudacityMessageBoxCaptionStr()
{ {
return _("Message"); return XO("Message");
} }

View File

@ -12,12 +12,13 @@
#define __AUDACITY_MESSAGE_BOX__ #define __AUDACITY_MESSAGE_BOX__
#include <wx/msgdlg.h> #include <wx/msgdlg.h>
#include "../Internat.h"
extern wxString AudacityMessageBoxCaptionStr(); extern TranslatableString AudacityMessageBoxCaptionStr();
// Do not use wxMessageBox!! Its default window title does not translate! // Do not use wxMessageBox!! Its default window title does not translate!
inline int AudacityMessageBox(const wxString& message, inline int AudacityMessageBox(const wxString& message,
const wxString& caption = AudacityMessageBoxCaptionStr(), const wxString& caption = AudacityMessageBoxCaptionStr().Translation(),
long style = wxOK | wxCENTRE, long style = wxOK | wxCENTRE,
wxWindow *parent = NULL, wxWindow *parent = NULL,
int x = wxDefaultCoord, int y = wxDefaultCoord) int x = wxDefaultCoord, int y = wxDefaultCoord)

View File

@ -111,7 +111,7 @@ class AUDACITY_DLL_API XMLFileWriter final : private wxFFile, public XMLWriter {
private: private:
void ThrowException( void ThrowException(
const wxFileName &fileName, const wxString &caption) const wxFileName &fileName, const TranslatableString &caption)
{ {
throw FileException{ FileException::Cause::Write, fileName, caption }; throw FileException{ FileException::Cause::Write, fileName, caption };
} }
@ -121,7 +121,7 @@ class AUDACITY_DLL_API XMLFileWriter final : private wxFFile, public XMLWriter {
void CloseWithoutEndingTags(); // for auto-save files void CloseWithoutEndingTags(); // for auto-save files
const FilePath mOutputPath; const FilePath mOutputPath;
const wxString mCaption; const TranslatableString mCaption;
FilePath mBackupName; FilePath mBackupName;
const bool mKeepBackup; const bool mKeepBackup;