From 503ccabdd8eeb71c9b35b970032a3db068266885 Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Sat, 7 Dec 2019 10:04:35 -0500 Subject: [PATCH] TranslatableString caption & message in MessageBoxException --- src/AudacityException.cpp | 8 ++++---- src/AudacityException.h | 16 ++++++++-------- src/FileException.cpp | 15 +++++++-------- src/FileException.h | 4 ++-- src/InconsistencyException.cpp | 16 +++++++--------- src/InconsistencyException.h | 4 ++-- src/Theme.cpp | 2 +- src/WaveClip.cpp | 2 +- src/WaveTrack.cpp | 6 +++--- src/blockfile/NotYetAvailableException.cpp | 9 ++++----- src/blockfile/NotYetAvailableException.h | 2 +- src/import/RawAudioGuess.cpp | 2 +- src/menus/EditMenus.cpp | 4 ++-- src/widgets/AudacityMessageBox.cpp | 4 ++-- src/widgets/AudacityMessageBox.h | 5 +++-- src/xml/XMLWriter.h | 4 ++-- 16 files changed, 50 insertions(+), 53 deletions(-) diff --git a/src/AudacityException.cpp b/src/AudacityException.cpp index 310646fbb..a40fd051b 100644 --- a/src/AudacityException.cpp +++ b/src/AudacityException.cpp @@ -32,7 +32,7 @@ AudacityException::~AudacityException() wxAtomicInt sOutstandingMessages {}; -MessageBoxException::MessageBoxException( const wxString &caption_ ) +MessageBoxException::MessageBoxException( const TranslatableString &caption_ ) : caption{ caption_ } { if (!caption.empty()) @@ -80,7 +80,7 @@ SimpleMessageBoxException::~SimpleMessageBoxException() { } -wxString SimpleMessageBoxException::ErrorMessage() const +TranslatableString SimpleMessageBoxException::ErrorMessage() const { return message; } @@ -96,8 +96,8 @@ void MessageBoxException::DelayedHandlerAction() // give the user no useful added information. if ( wxAtomicDec( sOutstandingMessages ) == 0 ) ::AudacityMessageBox( - ErrorMessage(), - caption.empty() ? AudacityMessageBoxCaptionStr() : caption, + ErrorMessage().Translation(), + (caption.empty() ? AudacityMessageBoxCaptionStr() : caption).Translation(), wxICON_ERROR ); moved = true; diff --git a/src/AudacityException.h b/src/AudacityException.h index 21552d309..c7b97985d 100644 --- a/src/AudacityException.h +++ b/src/AudacityException.h @@ -54,17 +54,17 @@ class MessageBoxException /* not final */ : public AudacityException protected: // 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( const MessageBoxException& ); MessageBoxException &operator = ( MessageBoxException && ); - // Format a default, internationalized error message for this exception. - virtual wxString ErrorMessage() const = 0; + // Format a default error message for this exception. + virtual TranslatableString ErrorMessage() const = 0; private: - wxString caption; + TranslatableString caption; mutable bool moved { false }; }; @@ -72,8 +72,8 @@ private: class SimpleMessageBoxException /* not final */ : public MessageBoxException { public: - explicit SimpleMessageBoxException( const wxString &message_, - const wxString &caption = _("Message") ) + explicit SimpleMessageBoxException( const TranslatableString &message_, + const TranslatableString &caption = XO("Message") ) : MessageBoxException{ caption } , message{ message_ } {} @@ -84,10 +84,10 @@ public: SimpleMessageBoxException && ) PROHIBITED; // Format a default, internationalized error message for this exception. - virtual wxString ErrorMessage() const override; + virtual TranslatableString ErrorMessage() const override; private: - wxString message; + TranslatableString message; }; diff --git a/src/FileException.cpp b/src/FileException.cpp index 05564b77c..4be1b35aa 100644 --- a/src/FileException.cpp +++ b/src/FileException.cpp @@ -15,24 +15,24 @@ FileException::~FileException() { } -wxString FileException::ErrorMessage() const +TranslatableString FileException::ErrorMessage() const { - wxString format; + TranslatableString format; switch (cause) { case Cause::Open: - format = _("Audacity failed to open a file in %s."); + format = XO("Audacity failed to open a file in %s."); break; 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; case Cause::Write: 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."); break; case Cause::Rename: 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: break; } @@ -54,7 +54,6 @@ _("Audacity successfully wrote a file in %s but failed to rename it as %s."); #endif - return wxString::Format( - format, target, renameTarget.GetFullName() ); + return format.Format( target, renameTarget.GetFullName() ); } diff --git a/src/FileException.h b/src/FileException.h index e357dd9ea..48b942e84 100644 --- a/src/FileException.h +++ b/src/FileException.h @@ -19,7 +19,7 @@ public: explicit FileException ( Cause cause_, const wxFileName &fileName_, - const wxString &caption = _("File Error"), + const TranslatableString &caption = XO("File Error"), const wxFileName &renameTarget_ = {}) : MessageBoxException{ caption } , cause{ cause_ }, fileName{ fileName_ }, renameTarget{ renameTarget_ } @@ -38,7 +38,7 @@ public: protected: // Format a default, internationalized error message for this exception. - wxString ErrorMessage() const override; + TranslatableString ErrorMessage() const override; public: Cause cause; diff --git a/src/InconsistencyException.cpp b/src/InconsistencyException.cpp index 856a02c58..5f699b3c2 100644 --- a/src/InconsistencyException.cpp +++ b/src/InconsistencyException.cpp @@ -13,7 +13,7 @@ InconsistencyException::~InconsistencyException() { } -wxString InconsistencyException::ErrorMessage() const +TranslatableString InconsistencyException::ErrorMessage() const { // Shorten the path wxString path { file }; @@ -23,14 +23,12 @@ wxString InconsistencyException::ErrorMessage() const path = path.Mid(index + sub.size()); #ifdef __func__ - return wxString::Format( -_("Internal error in %s at %s line %d.\nPlease inform the Audacity team at https://forum.audacityteam.org/."), - func, path, line - ); + return +XO("Internal error in %s at %s line %d.\nPlease inform the Audacity team at https://forum.audacityteam.org/.") + .Format( func, path, line ); #else - return wxString::Format( -_("Internal error at %s line %d.\nPlease inform the Audacity team at https://forum.audacityteam.org/."), - path, line - ); + return +XO("Internal error at %s line %d.\nPlease inform the Audacity team at https://forum.audacityteam.org/.") + .Format( path, line ); #endif } diff --git a/src/InconsistencyException.h b/src/InconsistencyException.h index 78477b263..ef4a47d4b 100644 --- a/src/InconsistencyException.h +++ b/src/InconsistencyException.h @@ -22,7 +22,7 @@ public: explicit InconsistencyException ( const char *fn, const char *f, unsigned l ) - : MessageBoxException{ _("Internal Error") } + : MessageBoxException{ XO("Internal Error") } , func { fn }, file { f }, line { l } {} @@ -49,7 +49,7 @@ public: private: // Format a default, internationalized error message for this exception. - wxString ErrorMessage() const override; + TranslatableString ErrorMessage() const override; const char *func {}; const char *file {}; diff --git a/src/Theme.cpp b/src/Theme.cpp index ffe913ef2..fa404070b 100644 --- a/src/Theme.cpp +++ b/src/Theme.cpp @@ -1159,7 +1159,7 @@ void ThemeBase::SaveComponents() wxString::Format( _("Some required files in:\n %s\nwere already present. Overwrite?"), FileNames::ThemeComponentsDir()), - AudacityMessageBoxCaptionStr(), + AudacityMessageBoxCaptionStr().Translation(), wxYES_NO | wxNO_DEFAULT); if(result == wxNO) return; diff --git a/src/WaveClip.cpp b/src/WaveClip.cpp index 5649f63f2..8c5a6e9d7 100644 --- a/src/WaveClip.cpp +++ b/src/WaveClip.cpp @@ -1952,7 +1952,7 @@ void WaveClip::Resample(int rate, ProgressDialog *progress) if (error) throw SimpleMessageBoxException{ - _("Resampling failed.") + XO("Resampling failed.") }; else { diff --git a/src/WaveTrack.cpp b/src/WaveTrack.cpp index 83508ea4a..d403db207 100644 --- a/src/WaveTrack.cpp +++ b/src/WaveTrack.cpp @@ -1228,7 +1228,7 @@ void WaveTrack::Paste(double t0, const Track *src) // STRONG-GUARANTEE in case of this path // not that it matters. 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 // not that it matters. 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) @@ -2381,7 +2381,7 @@ void WaveTrack::ExpandCutLine(double cutLinePosition, double* cutlineStart, clip->GetEndTime() + end - start > clip2->GetStartTime()) // STRONG-GUARANTEE in case of this path 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") }; } } diff --git a/src/blockfile/NotYetAvailableException.cpp b/src/blockfile/NotYetAvailableException.cpp index 39c46d22f..b22217c7e 100644 --- a/src/blockfile/NotYetAvailableException.cpp +++ b/src/blockfile/NotYetAvailableException.cpp @@ -13,10 +13,9 @@ NotYetAvailableException::~NotYetAvailableException() { } -wxString NotYetAvailableException::ErrorMessage() const +TranslatableString NotYetAvailableException::ErrorMessage() const { - return wxString::Format( - _("This operation cannot be done until importation of %s completes."), - fileName.GetFullName() - ); + return + XO("This operation cannot be done until importation of %s completes.") + .Format( fileName.GetFullName() ); } diff --git a/src/blockfile/NotYetAvailableException.h b/src/blockfile/NotYetAvailableException.h index c61360601..dd89bdd07 100644 --- a/src/blockfile/NotYetAvailableException.h +++ b/src/blockfile/NotYetAvailableException.h @@ -24,7 +24,7 @@ public: ~NotYetAvailableException(); protected: - wxString ErrorMessage() const override; + TranslatableString ErrorMessage() const override; }; #endif diff --git a/src/import/RawAudioGuess.cpp b/src/import/RawAudioGuess.cpp index 97e0749e0..710df0787 100644 --- a/src/import/RawAudioGuess.cpp +++ b/src/import/RawAudioGuess.cpp @@ -209,7 +209,7 @@ static void Extract(bool bits16, } if( dataSizeIn < 1 ) - throw SimpleMessageBoxException{_("Bad data size")}; + throw SimpleMessageBoxException{XO("Bad data size")}; size_t dataSize = (size_t)dataSizeIn; diff --git a/src/menus/EditMenus.cpp b/src/menus/EditMenus.cpp index b6572d792..23b364daa 100644 --- a/src/menus/EditMenus.cpp +++ b/src/menus/EditMenus.cpp @@ -468,7 +468,7 @@ void OnPaste(const CommandContext &context) // Throw, so that any previous changes to the project in this loop // are discarded. 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 @@ -496,7 +496,7 @@ void OnPaste(const CommandContext &context) // Throw, so that any previous changes to the project in this // loop are discarded. throw SimpleMessageBoxException{ - _("Copying stereo audio into a mono track is not allowed.") + XO("Copying stereo audio into a mono track is not allowed.") }; } } diff --git a/src/widgets/AudacityMessageBox.cpp b/src/widgets/AudacityMessageBox.cpp index 834601dbe..1f98bc255 100644 --- a/src/widgets/AudacityMessageBox.cpp +++ b/src/widgets/AudacityMessageBox.cpp @@ -11,7 +11,7 @@ #include "AudacityMessageBox.h" #include "../Internat.h" -wxString AudacityMessageBoxCaptionStr() +TranslatableString AudacityMessageBoxCaptionStr() { - return _("Message"); + return XO("Message"); } diff --git a/src/widgets/AudacityMessageBox.h b/src/widgets/AudacityMessageBox.h index f2f9f0547..1ad739b1d 100644 --- a/src/widgets/AudacityMessageBox.h +++ b/src/widgets/AudacityMessageBox.h @@ -12,12 +12,13 @@ #define __AUDACITY_MESSAGE_BOX__ #include +#include "../Internat.h" -extern wxString AudacityMessageBoxCaptionStr(); +extern TranslatableString AudacityMessageBoxCaptionStr(); // Do not use wxMessageBox!! Its default window title does not translate! inline int AudacityMessageBox(const wxString& message, - const wxString& caption = AudacityMessageBoxCaptionStr(), + const wxString& caption = AudacityMessageBoxCaptionStr().Translation(), long style = wxOK | wxCENTRE, wxWindow *parent = NULL, int x = wxDefaultCoord, int y = wxDefaultCoord) diff --git a/src/xml/XMLWriter.h b/src/xml/XMLWriter.h index 885cf9f98..ffe98bfc1 100644 --- a/src/xml/XMLWriter.h +++ b/src/xml/XMLWriter.h @@ -111,7 +111,7 @@ class AUDACITY_DLL_API XMLFileWriter final : private wxFFile, public XMLWriter { private: void ThrowException( - const wxFileName &fileName, const wxString &caption) + const wxFileName &fileName, const TranslatableString &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 const FilePath mOutputPath; - const wxString mCaption; + const TranslatableString mCaption; FilePath mBackupName; const bool mKeepBackup;