Skip to content

Commit d32d464

Browse files
committed
Uses of TranslatableString in src/import
1 parent f137bc1 commit d32d464

16 files changed

+175
-85
lines changed

include/audacity/ImporterInterface.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class ImporterInterface : public ComponentInterface
6767

6868
// Get a description of the file type this importer can import.
6969
// Examples: "Ogg Vorbis", "MP3", "Uncompressed PCM"
70-
virtual wxString GetPluginFormatDescription() = 0;
70+
virtual TranslatableString GetPluginFormatDescription() = 0;
7171

7272
// Get a list of extensions this plugin expects to be able to
7373
// import. If a filename matches any of these extensions,
@@ -134,7 +134,7 @@ class ImporterClientInterface
134134
// This is similar to GetImporterDescription, but if possible the
135135
// importer will return a more specific description of the
136136
// specific file that is open.
137-
virtual wxString GetFileDescription() = 0;
137+
virtual TranslatableString GetFileDescription() = 0;
138138

139139
// Return stream descriptions list
140140
virtual void GetStreamInfo(wxArrayString & streamInfo) = 0;

src/BatchProcessDialog.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ void ApplyMacroDialog::OnApplyToFiles(wxCommandEvent & WXUNUSED(event))
346346
for (const auto &format : l) {
347347
const Format *f = &format;
348348

349-
wxString newfilter = f->formatName + wxT("|");
349+
wxString newfilter = f->formatName.Translation() + wxT("|");
350350
for (size_t i = 0; i < f->formatExtensions.size(); i++) {
351351
if (!newfilter.Contains(wxT("*.") + f->formatExtensions[i] + wxT(";")))
352352
newfilter += wxT("*.") + f->formatExtensions[i] + wxT(";");

src/PluginManager.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,11 @@ class PluginDescriptor
111111
// Importer plugins only
112112

113113
const wxString & GetImporterIdentifier() const;
114-
const wxString & GetImporterFilterDescription() const;
114+
const TranslatableString & GetImporterFilterDescription() const;
115115
const FileExtensions & GetImporterExtensions() const;
116116

117117
void SetImporterIdentifier(const wxString & identifier);
118-
void SetImporterFilterDescription(const wxString & filterDesc);
118+
void SetImporterFilterDescription(const TranslatableString & filterDesc);
119119
void SetImporterExtensions(FileExtensions extensions);
120120

121121
private:

src/ProjectFileManager.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -986,7 +986,7 @@ wxArrayString ProjectFileManager::ShowOpenDialog(const wxString &extraformat, co
986986
/* this loop runs once per supported _format_ */
987987
const Format *f = &format;
988988

989-
wxString newfilter = f->formatName + wxT("|");
989+
wxString newfilter = f->formatName.Translation() + wxT("|");
990990
// bung format name into string plus | separator
991991
for (size_t i = 0; i < f->formatExtensions.size(); i++) {
992992
/* this loop runs once per valid _file extension_ for file containing
@@ -1661,7 +1661,7 @@ bool ProjectFileManager::Import(
16611661
auto &dirManager = DirManager::Get( project );
16621662
auto oldTags = Tags::Get( project ).shared_from_this();
16631663
TrackHolders newTracks;
1664-
wxString errorMessage;
1664+
TranslatableString errorMessage;
16651665

16661666
{
16671667
// Backup Tags, before the import. Be prepared to roll back changes.
@@ -1683,7 +1683,7 @@ bool ProjectFileManager::Import(
16831683
// Error message derived from Importer::Import
16841684
// Additional help via a Help button links to the manual.
16851685
ShowErrorDialog(&GetProjectFrame( project ), _("Error Importing"),
1686-
errorMessage, wxT("Importing_Audio"));
1686+
errorMessage.Translation(), wxT("Importing_Audio"));
16871687
}
16881688
if (!success)
16891689
return false;

src/import/Import.cpp

Lines changed: 57 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ bool Importer::Import(const FilePath &fName,
345345
TrackFactory *trackFactory,
346346
TrackHolders &tracks,
347347
Tags *tags,
348-
wxString &errorMessage)
348+
TranslatableString &errorMessage)
349349
{
350350
AudacityProject *pProj = GetActiveProject();
351351
auto cleanup = valueRestorer( pProj->mbBusyImporting, true );
@@ -356,7 +356,9 @@ bool Importer::Import(const FilePath &fName,
356356
#ifdef USE_MIDI
357357
// MIDI files must be imported, not opened
358358
if (FileNames::IsMidi(fName)) {
359-
errorMessage.Printf(_("\"%s\" \nis a MIDI file, not an audio file. \nAudacity cannot open this type of file for playing, but you can\nedit it by clicking File > Import > MIDI."), fName);
359+
errorMessage = XO(
360+
"\"%s\" \nis a MIDI file, not an audio file. \nAudacity cannot open this type of file for playing, but you can\nedit it by clicking File > Import > MIDI.")
361+
.Format( fName );
360362
return false;
361363
}
362364
#endif
@@ -391,7 +393,7 @@ bool Importer::Import(const FilePath &fName,
391393
// store localized strings!
392394
// The bad consequences of a change of locale are not severe -- only that
393395
// a default choice of file type for an open dialog is not remembered
394-
if (plugin->GetPluginFormatDescription().CompareTo(type) == 0)
396+
if (plugin->GetPluginFormatDescription().Translation() == type )
395397
{
396398
// This plugin corresponds to user-selected filter, try it first.
397399
wxLogDebug(wxT("Inserting %s"),plugin->GetPluginStringID());
@@ -587,9 +589,8 @@ bool Importer::Import(const FilePath &fName,
587589
{
588590
if( unusableImportPlugin->SupportsExtension(extension) )
589591
{
590-
errorMessage.Printf(_("This version of Audacity was not compiled with %s support."),
591-
unusableImportPlugin->
592-
GetPluginFormatDescription());
592+
errorMessage = XO("This version of Audacity was not compiled with %s support.")
593+
.Format( unusableImportPlugin->GetPluginFormatDescription() );
593594
return false;
594595
}
595596
}
@@ -601,101 +602,131 @@ bool Importer::Import(const FilePath &fName,
601602
// if someone has sent us a .cda file, send them away
602603
if (extension.IsSameAs(wxT("cda"), false)) {
603604
/* i18n-hint: %s will be the filename */
604-
errorMessage.Printf(_("\"%s\" is an audio CD track. \nAudacity cannot open audio CDs directly. \nExtract (rip) the CD tracks to an audio format that \nAudacity can import, such as WAV or AIFF."), fName);
605+
errorMessage = XO(
606+
"\"%s\" is an audio CD track. \nAudacity cannot open audio CDs directly. \nExtract (rip) the CD tracks to an audio format that \nAudacity can import, such as WAV or AIFF.")
607+
.Format( fName );
605608
return false;
606609
}
607610

608611
// playlist type files
609612
if ((extension.IsSameAs(wxT("m3u"), false))||(extension.IsSameAs(wxT("ram"), false))||(extension.IsSameAs(wxT("pls"), false))) {
610-
errorMessage.Printf(_("\"%s\" is a playlist file. \nAudacity cannot open this file because it only contains links to other files. \nYou may be able to open it in a text editor and download the actual audio files."), fName);
613+
errorMessage = XO(
614+
"\"%s\" is a playlist file. \nAudacity cannot open this file because it only contains links to other files. \nYou may be able to open it in a text editor and download the actual audio files.")
615+
.Format( fName );
611616
return false;
612617
}
613618
//WMA files of various forms
614619
if ((extension.IsSameAs(wxT("wma"), false))||(extension.IsSameAs(wxT("asf"), false))) {
615-
errorMessage.Printf(_("\"%s\" is a Windows Media Audio file. \nAudacity cannot open this type of file due to patent restrictions. \nYou need to convert it to a supported audio format, such as WAV or AIFF."), fName);
620+
errorMessage = XO(
621+
"\"%s\" is a Windows Media Audio file. \nAudacity cannot open this type of file due to patent restrictions. \nYou need to convert it to a supported audio format, such as WAV or AIFF.")
622+
.Format( fName );
616623
return false;
617624
}
618625
//AAC files of various forms (probably not encrypted)
619626
if ((extension.IsSameAs(wxT("aac"), false))||(extension.IsSameAs(wxT("m4a"), false))||(extension.IsSameAs(wxT("m4r"), false))||(extension.IsSameAs(wxT("mp4"), false))) {
620-
errorMessage.Printf(_("\"%s\" is an Advanced Audio Coding file.\nWithout the optional FFmpeg library, Audacity cannot open this type of file.\nOtherwise, you need to convert it to a supported audio format, such as WAV or AIFF."), fName);
627+
errorMessage = XO(
628+
"\"%s\" is an Advanced Audio Coding file.\nWithout the optional FFmpeg library, Audacity cannot open this type of file.\nOtherwise, you need to convert it to a supported audio format, such as WAV or AIFF.")
629+
.Format( fName );
621630
return false;
622631
}
623632
// encrypted itunes files
624633
if ((extension.IsSameAs(wxT("m4p"), false))) {
625-
errorMessage.Printf(_("\"%s\" is an encrypted audio file. \nThese typically are from an online music store. \nAudacity cannot open this type of file due to the encryption. \nTry recording the file into Audacity, or burn it to audio CD then \nextract the CD track to a supported audio format such as WAV or AIFF."), fName);
634+
errorMessage = XO(
635+
"\"%s\" is an encrypted audio file. \nThese typically are from an online music store. \nAudacity cannot open this type of file due to the encryption. \nTry recording the file into Audacity, or burn it to audio CD then \nextract the CD track to a supported audio format such as WAV or AIFF.")
636+
.Format( fName );
626637
return false;
627638
}
628639
// Real Inc. files of various sorts
629640
if ((extension.IsSameAs(wxT("ra"), false))||(extension.IsSameAs(wxT("rm"), false))||(extension.IsSameAs(wxT("rpm"), false))) {
630-
errorMessage.Printf(_("\"%s\" is a RealPlayer media file. \nAudacity cannot open this proprietary format. \nYou need to convert it to a supported audio format, such as WAV or AIFF."), fName);
641+
errorMessage = XO(
642+
"\"%s\" is a RealPlayer media file. \nAudacity cannot open this proprietary format. \nYou need to convert it to a supported audio format, such as WAV or AIFF.")
643+
.Format( fName );
631644
return false;
632645
}
633646

634647
// Other notes-based formats
635648
if ((extension.IsSameAs(wxT("kar"), false))||(extension.IsSameAs(wxT("mod"), false))||(extension.IsSameAs(wxT("rmi"), false))) {
636-
errorMessage.Printf(_("\"%s\" is a notes-based file, not an audio file. \nAudacity cannot open this type of file. \nTry converting it to an audio file such as WAV or AIFF and \nthen import it, or record it into Audacity."), fName);
649+
errorMessage = XO(
650+
"\"%s\" is a notes-based file, not an audio file. \nAudacity cannot open this type of file. \nTry converting it to an audio file such as WAV or AIFF and \nthen import it, or record it into Audacity.")
651+
.Format( fName );
637652
return false;
638653
}
639654

640655
// MusePack files
641656
if ((extension.IsSameAs(wxT("mp+"), false))||(extension.IsSameAs(wxT("mpc"), false))||(extension.IsSameAs(wxT("mpp"), false))) {
642-
errorMessage.Printf(_("\"%s\" is a Musepack audio file. \nAudacity cannot open this type of file. \nIf you think it might be an mp3 file, rename it to end with \".mp3\" \nand try importing it again. Otherwise you need to convert it to a supported audio \nformat, such as WAV or AIFF."), fName);
657+
errorMessage = XO(
658+
"\"%s\" is a Musepack audio file. \nAudacity cannot open this type of file. \nIf you think it might be an mp3 file, rename it to end with \".mp3\" \nand try importing it again. Otherwise you need to convert it to a supported audio \nformat, such as WAV or AIFF.")
659+
.Format( fName );
643660
return false;
644661
}
645662

646663
// WavPack files
647664
if ((extension.IsSameAs(wxT("wv"), false))||(extension.IsSameAs(wxT("wvc"), false))) {
648-
errorMessage.Printf(_("\"%s\" is a Wavpack audio file. \nAudacity cannot open this type of file. \nYou need to convert it to a supported audio format, such as WAV or AIFF."), fName);
665+
errorMessage = XO(
666+
"\"%s\" is a Wavpack audio file. \nAudacity cannot open this type of file. \nYou need to convert it to a supported audio format, such as WAV or AIFF.")
667+
.Format( fName );
649668
return false;
650669
}
651670

652671
// AC3 files
653672
if ((extension.IsSameAs(wxT("ac3"), false))) {
654-
errorMessage.Printf(_("\"%s\" is a Dolby Digital audio file. \nAudacity cannot currently open this type of file. \nYou need to convert it to a supported audio format, such as WAV or AIFF."), fName);
673+
errorMessage = XO(
674+
"\"%s\" is a Dolby Digital audio file. \nAudacity cannot currently open this type of file. \nYou need to convert it to a supported audio format, such as WAV or AIFF.")
675+
.Format( fName );
655676
return false;
656677
}
657678

658679
// Speex files
659680
if ((extension.IsSameAs(wxT("spx"), false))) {
660-
errorMessage.Printf(_("\"%s\" is an Ogg Speex audio file. \nAudacity cannot currently open this type of file. \nYou need to convert it to a supported audio format, such as WAV or AIFF."), fName);
681+
errorMessage = XO(
682+
"\"%s\" is an Ogg Speex audio file. \nAudacity cannot currently open this type of file. \nYou need to convert it to a supported audio format, such as WAV or AIFF.")
683+
.Format( fName );
661684
return false;
662685
}
663686

664687
// Video files of various forms
665688
if ((extension.IsSameAs(wxT("mpg"), false))||(extension.IsSameAs(wxT("mpeg"), false))||(extension.IsSameAs(wxT("avi"), false))||(extension.IsSameAs(wxT("wmv"), false))||(extension.IsSameAs(wxT("rv"), false))) {
666-
errorMessage.Printf(_("\"%s\" is a video file. \nAudacity cannot currently open this type of file. \nYou need to extract the audio to a supported format, such as WAV or AIFF."), fName);
689+
errorMessage = XO(
690+
"\"%s\" is a video file. \nAudacity cannot currently open this type of file. \nYou need to extract the audio to a supported format, such as WAV or AIFF.")
691+
.Format( fName );
667692
return false;
668693
}
669694

670695
// Audacity project
671696
if (extension.IsSameAs(wxT("aup"), false)) {
672-
errorMessage.Printf(_("\"%s\" is an Audacity Project file. \nUse the 'File > Open' command to open Audacity Projects."), fName);
697+
errorMessage = XO(
698+
"\"%s\" is an Audacity Project file. \nUse the 'File > Open' command to open Audacity Projects.")
699+
.Format( fName );
673700
return false;
674701
}
675702

676703
if( !wxFileExists(fName)){
677-
errorMessage.Printf(_("File \"%s\" not found."), fName);
704+
errorMessage = XO( "File \"%s\" not found.").Format( fName );
678705
return false;
679706
}
680707

681708
// we were not able to recognize the file type
682-
errorMessage.Printf(_("Audacity did not recognize the type of the file '%s'.\nTry installing FFmpeg. For uncompressed files, also try File > Import > Raw Data."),fName);
709+
errorMessage = XO(
710+
"Audacity did not recognize the type of the file '%s'.\nTry installing FFmpeg. For uncompressed files, also try File > Import > Raw Data.")
711+
.Format( fName );
683712
}
684713
else
685714
{
686715
// We DO have a plugin for this file, but import failed.
687-
wxString pluglist;
716+
TranslatableString pluglist;
688717

689718
for (const auto &plugin : compatiblePlugins)
690719
{
691720
if (pluglist.empty())
692721
pluglist = plugin->GetPluginFormatDescription();
693722
else
694-
pluglist = wxString::Format( _("%s, %s"),
695-
pluglist, plugin->GetPluginFormatDescription() );
723+
pluglist = XO("%s, %s")
724+
.Format( pluglist, plugin->GetPluginFormatDescription() );
696725
}
697726

698-
errorMessage.Printf(_("Audacity recognized the type of the file '%s'.\nImporters supposedly supporting such files are:\n%s,\nbut none of them understood this file format."),fName, pluglist);
727+
errorMessage = XO(
728+
"Audacity recognized the type of the file '%s'.\nImporters supposedly supporting such files are:\n%s,\nbut none of them understood this file format.")
729+
.Format( fName, pluglist );
699730
}
700731

701732
return false;
@@ -774,9 +805,8 @@ ImportFileHandle::~ImportFileHandle()
774805
void ImportFileHandle::CreateProgress()
775806
{
776807
wxFileName ff( mFilename );
777-
wxString title;
778808

779-
title.Printf(_("Importing %s"), GetFileDescription());
809+
auto title = XO("Importing %s").Format( GetFileDescription() ).Translation();
780810
mProgress = std::make_unique< ProgressDialog >( title, ff.GetFullName() );
781811
}
782812

src/import/Import.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ typedef bool (*progress_callback_t)( void *userData, float percent );
3131

3232
class Format {
3333
public:
34-
wxString formatName;
34+
TranslatableString formatName;
3535
FileExtensions formatExtensions;
3636

37-
Format(const wxString &_formatName,
37+
Format(const TranslatableString &_formatName,
3838
FileExtensions _formatExtensions):
3939
formatName(_formatName),
4040
formatExtensions( std::move( _formatExtensions ) )
@@ -155,7 +155,7 @@ class Importer {
155155
TrackFactory *trackFactory,
156156
TrackHolders &tracks,
157157
Tags *tags,
158-
wxString &errorMessage);
158+
TranslatableString &errorMessage);
159159

160160
private:
161161
static Importer mInstance;

src/import/ImportFFmpeg.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Licensed under the GNU General Public License v2 or later
3939
#include "../widgets/ProgressDialog.h"
4040

4141

42-
#define DESC _("FFmpeg-compatible files")
42+
#define DESC XO("FFmpeg-compatible files")
4343

4444
//TODO: remove non-audio extensions
4545
#if defined(USE_FFMPEG)
@@ -180,7 +180,7 @@ class FFmpegImportPlugin final : public ImportPlugin
180180
~FFmpegImportPlugin() { }
181181

182182
wxString GetPluginStringID() override { return wxT("libav"); }
183-
wxString GetPluginFormatDescription() override;
183+
TranslatableString GetPluginFormatDescription() override;
184184

185185
///! Probes the file and opens it if appropriate
186186
std::unique_ptr<ImportFileHandle> Open(const FilePath &Filename) override;
@@ -204,7 +204,7 @@ class FFmpegImportFileHandle final : public ImportFileHandle
204204
bool InitCodecs();
205205

206206

207-
wxString GetFileDescription() override;
207+
TranslatableString GetFileDescription() override;
208208
ByteCount GetFileUncompressedBytes() override;
209209

210210
///! Imports audio
@@ -286,7 +286,7 @@ class FFmpegImportFileHandle final : public ImportFileHandle
286286
};
287287

288288

289-
wxString FFmpegImportPlugin::GetPluginFormatDescription()
289+
TranslatableString FFmpegImportPlugin::GetPluginFormatDescription()
290290
{
291291
return DESC;
292292
}
@@ -465,7 +465,7 @@ bool FFmpegImportFileHandle::InitCodecs()
465465
return true;
466466
}
467467

468-
wxString FFmpegImportFileHandle::GetFileDescription()
468+
TranslatableString FFmpegImportFileHandle::GetFileDescription()
469469
{
470470
return DESC;
471471
}

src/import/ImportFLAC.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949

5050
#define FLAC_HEADER "fLaC"
5151

52-
#define DESC _("FLAC files")
52+
#define DESC XO("FLAC files")
5353

5454
static const auto exts = {
5555
wxT("flac"),
@@ -134,7 +134,7 @@ class FLACImportPlugin final : public ImportPlugin
134134
~FLACImportPlugin() { }
135135

136136
wxString GetPluginStringID() override { return wxT("libflac"); }
137-
wxString GetPluginFormatDescription() override;
137+
TranslatableString GetPluginFormatDescription() override;
138138
std::unique_ptr<ImportFileHandle> Open(const FilePath &Filename) override;
139139

140140
unsigned SequenceNumber() const override;
@@ -150,7 +150,7 @@ class FLACImportFileHandle final : public ImportFileHandle
150150

151151
bool Init();
152152

153-
wxString GetFileDescription() override;
153+
TranslatableString GetFileDescription() override;
154154
ByteCount GetFileUncompressedBytes() override;
155155
ProgressResult Import(TrackFactory *trackFactory, TrackHolders &outTracks,
156156
Tags *tags) override;
@@ -285,7 +285,7 @@ FLAC__StreamDecoderWriteStatus MyFLACFile::write_callback(const FLAC__Frame *fra
285285
}, MakeSimpleGuard(FLAC__STREAM_DECODER_WRITE_STATUS_ABORT) );
286286
}
287287

288-
wxString FLACImportPlugin::GetPluginFormatDescription()
288+
TranslatableString FLACImportPlugin::GetPluginFormatDescription()
289289
{
290290
return DESC;
291291
}
@@ -425,7 +425,7 @@ bool FLACImportFileHandle::Init()
425425
return true;
426426
}
427427

428-
wxString FLACImportFileHandle::GetFileDescription()
428+
TranslatableString FLACImportFileHandle::GetFileDescription()
429429
{
430430
return DESC;
431431
}

0 commit comments

Comments
 (0)