Define and use function Verbatim...

... in cases of "TranslatableString" that are not really translated.

This makes it easier to scan the code for such unusual constructions of
TranslatableString, distinct from mere mentions of the TranslatableString type.
This commit is contained in:
Paul Licameli 2019-12-19 16:20:41 -05:00
parent a70524446e
commit e3ea93a624
27 changed files with 92 additions and 78 deletions

View File

@ -308,23 +308,20 @@ class TranslatableString : private wxString {
template< size_t N > struct PluralTemp;
public:
// A special string value that will have no screen reader pronunciation
static const TranslatableString Inaudible;
// A multi-purpose function, depending on the enum argument; the string
// argument is unused in some cases
// If there is no function, defaults are empty context string, no plurals,
// and no substitutions
using Formatter = std::function< wxString(const wxString &, Request) >;
// This special formatter causes msgids to be used verbatim, not looked up
// in any catalog, so Translation() and Debug() return the same
static const Formatter NullContextFormatter;
TranslatableString() {}
// Supply {} for the second argument to cause lookup of the msgid with
// empty context string (default context) rather than the null context
explicit TranslatableString(
wxString str, Formatter formatter = NullContextFormatter
)
explicit TranslatableString( wxString str, Formatter formatter )
: mFormatter{ std::move(formatter) }
{
this->wxString::swap( str );
@ -472,6 +469,18 @@ public:
{ return TranslatableString{ *this }.Strip( options ); }
private:
static const Formatter NullContextFormatter;
// Construct a TranslatableString that does no translation but passes
// str verbatim
explicit TranslatableString( wxString str )
: mFormatter{ NullContextFormatter }
{
this->wxString::swap( str );
}
friend TranslatableString Verbatim( wxString str );
enum class Request {
Context, // return a disambiguating context string
Format, // Given the msgid, format the string for end users
@ -544,9 +553,6 @@ inline TranslatableString operator +(
using TranslatableStrings = std::vector<TranslatableString>;
// A special string value that will have no screen reader pronunciation
extern const TranslatableString InaudibleString;
// For using std::unordered_map on TranslatableString
// Note: hashing on msgids only, which is not all of the information
namespace std
@ -561,6 +567,12 @@ namespace std
};
}
// Require calls to the one-argument constructor to go through this
// distinct global function name. This makes it easier to locate and
// review the uses of this function, separately from the uses of the type.
inline TranslatableString Verbatim( wxString str )
{ return TranslatableString( std::move( str ) ); }
// ----------------------------------------------------------------------------
// A native 64-bit integer...used when referring to any number of samples
// ----------------------------------------------------------------------------

View File

@ -1034,7 +1034,7 @@ void AboutDialog::AddCredit(
const wxString &name, TranslatableString format, Role role )
{
auto str = format.empty()
? TranslatableString{ name }
? Verbatim( name )
: TranslatableString{ format }.Format( name );
creditItems.emplace_back(std::move(str), role);
}

View File

@ -397,7 +397,7 @@ void ApplyMacroDialog::OnApplyToFiles(wxCommandEvent & WXUNUSED(event))
files.Sort();
wxDialogWrapper activityWin(this, wxID_ANY, TranslatableString{ GetTitle() });
wxDialogWrapper activityWin(this, wxID_ANY, Verbatim( GetTitle() ) );
activityWin.SetName();
ShuttleGui S(&activityWin, eIsCreating);

View File

@ -200,7 +200,7 @@ TranslatableString TitleText( const wxString & Key )
return XO("No Local Help");
}
// Uh oh, no translation...
return TranslatableString{ Key };
return Verbatim( Key );
}
static wxString HelpTextBuiltIn( const wxString & Key )

View File

@ -402,4 +402,4 @@ TranslatableString &TranslatableString::Join(
return *this;
}
const TranslatableString InaudibleString{ wxT("\a") };
const TranslatableString TranslatableString::Inaudible{ wxT("\a") };

View File

@ -202,7 +202,7 @@ void GetLanguages(
auto str = wxString::FromUTF8(utf8Name);
auto code = str.BeforeFirst(' ');
auto name = str.AfterFirst(' ');
localLanguageName[code] = TranslatableString{ name };
localLanguageName[code] = Verbatim( name );
}
return localLanguageName;
}();
@ -230,7 +230,7 @@ void GetLanguages(
wxString fullCode = info->CanonicalName;
wxString code = fullCode.Left(2);
TranslatableString name{ info->Description };
auto name = Verbatim( info->Description );
// Logic: Languages codes are sometimes hierarchical, with a
// general language code and then a subheading. For example,

View File

@ -175,7 +175,7 @@ MixerTrackCluster::MixerTrackCluster(wxWindow* parent,
mProject = project;
wxASSERT( pTrack );
SetName( TranslatableString{ mTrack->GetName() } );
SetName( Verbatim( mTrack->GetName() ) );
//this->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE));
this->SetBackgroundColour( theTheme.Colour( clrMedium ) );
@ -463,7 +463,7 @@ void MixerTrackCluster::UpdateForStateChange()
{
const wxString newName = mTrack->GetName();
if (newName != GetName()) {
SetName( TranslatableString{ newName } );
SetName( Verbatim( newName ) );
mStaticText_TrackName->SetLabel(newName);
mStaticText_TrackName->SetName(newName);
#if wxUSE_TOOLTIPS

View File

@ -988,8 +988,8 @@ void PluginRegistrationDialog::OnOK(wxCommandEvent & WXUNUSED(evt))
// we will leave the project window in an unusable state on OSX.
// See bug #1192.
{
ProgressDialog progress(
TranslatableString{ GetTitle() }, msg, pdlgHideStopButton);
ProgressDialog progress{
Verbatim( GetTitle() ), msg, pdlgHideStopButton };
progress.CenterOnParent();
int i = 0;

View File

@ -546,8 +546,8 @@ int TimerRecordDialog::RunWaitDialog()
ProjectAudioManager::Get( *pProject ).OnRecord(false);
bool bIsRecording = true;
auto sPostAction = TranslatableString{
m_pTimerAfterCompleteChoiceCtrl->GetStringSelection() };
auto sPostAction = Verbatim(
m_pTimerAfterCompleteChoiceCtrl->GetStringSelection() );
// Two column layout.
TimerProgressDialog::MessageTable columns{
@ -562,7 +562,7 @@ int TimerRecordDialog::RunWaitDialog()
},
{
GetDisplayDate(m_DateTime_Start) ,
TranslatableString{ m_TimeSpan_Duration.Format() },
Verbatim( m_TimeSpan_Duration.Format() ),
GetDisplayDate(m_DateTime_End) ,
{} ,
(m_bAutoSaveEnabled ? XO("Yes") : XO("No")) ,
@ -790,7 +790,7 @@ TranslatableString TimerRecordDialog::GetDisplayDate( wxDateTime & dt )
// Use default formatting
wxPrintf(wxT("%s\n"), dt.Format());
return TranslatableString{ dt.FormatDate() + wxT(" ") + dt.FormatTime() };
return Verbatim( dt.FormatDate() + wxT(" ") + dt.FormatTime() );
}
TimerRecordPathCtrl * TimerRecordDialog::NewPathControl(wxWindow *wParent, const int iID,
@ -1058,8 +1058,8 @@ void TimerRecordDialog::UpdateEnd()
ProgressResult TimerRecordDialog::WaitForStart()
{
// MY: The Waiting For Start dialog now shows what actions will occur after recording has completed
auto sPostAction = TranslatableString{
m_pTimerAfterCompleteChoiceCtrl->GetStringSelection() };
auto sPostAction = Verbatim(
m_pTimerAfterCompleteChoiceCtrl->GetStringSelection() );
// Two column layout.
TimerProgressDialog::MessageTable columns{
@ -1074,7 +1074,7 @@ ProgressResult TimerRecordDialog::WaitForStart()
},
{
GetDisplayDate(m_DateTime_Start),
TranslatableString{ m_TimeSpan_Duration.Format() },
Verbatim( m_TimeSpan_Duration.Format() ),
GetDisplayDate(m_DateTime_End) ,
{} ,
(m_bAutoSaveEnabled ? XO("Yes") : XO("No")) ,
@ -1106,8 +1106,8 @@ ProgressResult TimerRecordDialog::WaitForStart()
ProgressResult TimerRecordDialog::PreActionDelay(int iActionIndex, TimerRecordCompletedActions eCompletedActions)
{
auto sAction = TranslatableString{ m_pTimerAfterCompleteChoiceCtrl
->GetString(iActionIndex) };
auto sAction = Verbatim( m_pTimerAfterCompleteChoiceCtrl
->GetString(iActionIndex) );
/* i18n-hint: %s is one of "Do nothing", "Exit Audacity", "Restart system",
or "Shutdown system", and

View File

@ -985,7 +985,7 @@ TranslatableString CommandManager::DescribeCommandsAndShortcuts(
// Note: not putting this and other short format strings in the
// translation catalogs
auto piece = TranslatableString{wxT("%s%s")}
auto piece = Verbatim( wxT("%s%s") )
.Format( mark, pair.Msgid().Stripped() );
auto name = pair.Internal();
@ -1004,14 +1004,14 @@ TranslatableString CommandManager::DescribeCommandsAndShortcuts(
#endif
// The mark makes correctly placed parentheses for RTL, even
// in the case that the piece is untranslated.
piece = TranslatableString{format}.Format( piece, mark, keyString );
piece = Verbatim( format ).Format( piece, mark, keyString );
}
}
if (result.empty())
result = piece;
else
result = TranslatableString{ separatorFormat }.Format( result, piece );
result = Verbatim( separatorFormat ).Format( result, piece );
}
return result;
}
@ -1347,7 +1347,7 @@ TranslatableString CommandManager::GetPrefixedLabelFromName(const CommandID &nam
return {};
if (!entry->labelPrefix.empty())
return TranslatableString{wxT("%s - %s")}
return Verbatim( wxT("%s - %s") )
.Format(entry->labelPrefix, entry->label);
else
return entry->label;

View File

@ -2567,8 +2567,8 @@ public:
: wxPanelWrapper(parent)
{
// This fools NVDA into not saying "Panel" when the dialog gets focus
SetName(InaudibleString);
SetLabel(InaudibleString);
SetName(TranslatableString::Inaudible);
SetLabel(TranslatableString::Inaudible);
mAcceptsFocus = true;
}

View File

@ -988,7 +988,7 @@ void EffectEqualization::PopulateOrExchange(ShuttleGui & S)
{
wxString label;
label.Printf(wxT("%ld"), mM);
mMText = S.Name( TranslatableString{ label } )
mMText = S.Name( Verbatim( label ) )
// fix for bug 577 (NVDA/Narrator screen readers do not
// read static text in dialogs)
.AddVariableText(label);

View File

@ -618,7 +618,7 @@ unsigned VSTEffectsModule::DiscoverPluginsAtPath(
break;
case kKeyDescription:
proc.mDescription = TranslatableString{ val };
proc.mDescription = Verbatim( val );
keycount++;
break;

View File

@ -670,7 +670,7 @@ wxString LadspaEffect::GetVersion()
TranslatableString LadspaEffect::GetDescription()
{
return TranslatableString{ LAT1CTOWX(mData->Copyright) };
return Verbatim( LAT1CTOWX(mData->Copyright) );
}
// ============================================================================

View File

@ -188,7 +188,7 @@ NyquistEffect::NyquistEffect(const wxString &fName)
mFileName = fName;
// Use the file name verbatim as effect name.
// This is only a default name, overridden if we find a $name line:
mName = TranslatableString{ mFileName.GetName() };
mName = Verbatim( mFileName.GetName() );
mFileModified = mFileName.GetModificationTime();
ParseFile();
@ -2630,8 +2630,8 @@ void NyquistEffect::BuildEffectWindow(ShuttleGui & S)
}
else
{
auto prompt = wxString::Format(_("%s:"), ctrl.name);
S.AddPrompt(prompt);
auto prompt = XO("%s:").Format( ctrl.name );
S.AddPrompt( prompt.Translation() );
if (ctrl.type == NYQ_CTRL_STRING)
{
@ -2639,7 +2639,7 @@ void NyquistEffect::BuildEffectWindow(ShuttleGui & S)
auto item = S.Id(ID_Text + i)
.Validator<wxGenericValidator>(&ctrl.valStr)
.Name( TranslatableString{ prompt } )
.Name( prompt )
.AddTextBox( {}, wxT(""), 12);
}
else if (ctrl.type == NYQ_CTRL_CHOICE)
@ -2666,7 +2666,7 @@ void NyquistEffect::BuildEffectWindow(ShuttleGui & S)
mProjectRate,
options);
S
.Name( TranslatableString{ prompt } )
.Name( prompt )
.Position(wxALIGN_LEFT | wxALL)
.AddWindow(time);
}
@ -2691,7 +2691,7 @@ void NyquistEffect::BuildEffectWindow(ShuttleGui & S)
resolveFilePath(ctrl.valStr, defaultExtension);
wxTextCtrl *item = S.Id(ID_Text+i)
.Name( TranslatableString{ prompt } )
.Name( prompt )
.AddTextBox( {}, wxT(""), 40);
item->SetValidator(wxGenericValidator(&ctrl.valStr));
@ -2731,7 +2731,7 @@ void NyquistEffect::BuildEffectWindow(ShuttleGui & S)
(int) ctrl.low, (int) ctrl.high);
}
wxTextCtrl *item = S
.Name( TranslatableString{ prompt } )
.Name( prompt )
.AddTextBox( {}, wxT(""),
(ctrl.type == NYQ_CTRL_INT_TEXT ||
ctrl.type == NYQ_CTRL_FLOAT_TEXT) ? 25 : 12);

View File

@ -109,8 +109,8 @@ wxString VampEffect::GetVersion()
TranslatableString VampEffect::GetDescription()
{
return TranslatableString{
wxString::FromUTF8(mPlugin->getCopyright().c_str()) };
return Verbatim(
wxString::FromUTF8(mPlugin->getCopyright().c_str()) );
}
// ============================================================================
@ -608,8 +608,8 @@ void VampEffect::PopulateOrExchange(ShuttleGui & S)
mParameters[p].maxValue == 1.0)
{
S.Id(ID_Toggles + p);
mToggles[p] = S.ToolTip( TranslatableString{ tip } )
.Name( TranslatableString{ labelText } )
mToggles[p] = S.ToolTip( Verbatim( tip ) )
.Name( Verbatim( labelText ) )
.Position(wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL | wxALL)
.AddCheckBox( {},
value > 0.5 );
@ -637,8 +637,8 @@ void VampEffect::PopulateOrExchange(ShuttleGui & S)
}
S.Id(ID_Choices + p);
mChoices[p] = S.ToolTip( TranslatableString{ tip } )
.Name( TranslatableString{ labelText } )
mChoices[p] = S.ToolTip( Verbatim( tip ) )
.Name( Verbatim( labelText ) )
.Position(wxEXPAND | wxALIGN_CENTER_VERTICAL | wxALL)
.MinSize( { -1, -1 } )
.AddChoice( {}, choices, selected );
@ -654,8 +654,8 @@ void VampEffect::PopulateOrExchange(ShuttleGui & S)
float range = mParameters[p].maxValue - mParameters[p].minValue;
S.Id(ID_Texts + p);
mFields[p] = S.ToolTip( TranslatableString{ tip } )
.Name( TranslatableString{ labelText } )
mFields[p] = S.ToolTip( Verbatim( tip ) )
.Name( Verbatim( labelText ) )
.Position(wxALIGN_CENTER_VERTICAL | wxALL)
.Validator<FloatingPointValidator<float>>(
6, &mValues[p],
@ -671,8 +671,8 @@ void VampEffect::PopulateOrExchange(ShuttleGui & S)
S.AddPrompt(str);
S.Id(ID_Sliders + p);
mSliders[p] = S.ToolTip( TranslatableString{ tip } )
.Name( TranslatableString{ labelText } )
mSliders[p] = S.ToolTip( Verbatim( tip ) )
.Name( Verbatim( labelText ) )
.Style(wxSL_HORIZONTAL)
.MinSize( { 150, -1 } )
.AddSlider( {}, 0, 1000, 0);

View File

@ -280,7 +280,7 @@ void ExportPlugin::InitProgress(std::unique_ptr<ProgressDialog> &pDialog,
const wxFileNameWrapper &title, const TranslatableString &message)
{
return InitProgress(
pDialog, TranslatableString{ title.GetName() }, message );
pDialog, Verbatim( title.GetName() ), message );
}
//----------------------------------------------------------------------------

View File

@ -809,6 +809,6 @@ void ImportFileHandle::CreateProgress()
auto title = XO("Importing %s").Format( GetFileDescription() );
mProgress = std::make_unique< ProgressDialog >(
title, TranslatableString{ ff.GetFullName() } );
title, Verbatim( ff.GetFullName() ) );
}

View File

@ -653,7 +653,7 @@ void AddEffectMenuItemGroup(
wxString item = plug->GetPath();
if( plug->GetPluginType() == PluginTypeEffect )
temp2.push_back( Command( item,
TranslatableString{ item },
Verbatim( item ),
FN(OnEffect),
flags[i],
CommandManager::Options{}
@ -721,7 +721,7 @@ MenuTable::BaseItemPtrs PopulateMacrosMenu( CommandFlag flags )
for (i = 0; i < (int)names.size(); i++) {
auto MacroID = ApplyMacroDialog::MacroIdOfName( names[i] );
result.push_back( MenuTable::Command( MacroID,
TranslatableString{ names[i] }, // file name verbatim
Verbatim( names[i] ), // file name verbatim
FN(OnApplyMacroDirectly),
flags,
CommandManager::Options{}.AllowInMacros()

View File

@ -115,8 +115,9 @@ void DevicePrefs::GetNamesAndLabels()
const PaDeviceInfo *info = Pa_GetDeviceInfo(i);
if ((info!=NULL)&&(info->maxOutputChannels > 0 || info->maxInputChannels > 0)) {
wxString name = wxSafeConvertMB2WX(Pa_GetHostApiInfo(info->hostApi)->name);
if (!make_iterator_range(mHostNames).contains(TranslatableString{name})) {
mHostNames.push_back( TranslatableString{ name } );
if (!make_iterator_range(mHostNames)
.contains( Verbatim( name ) )) {
mHostNames.push_back( Verbatim( name ) );
mHostLabels.push_back(name);
}
}

View File

@ -572,11 +572,11 @@ void KeyConfigPrefs::OnSet(wxCommandEvent & WXUNUSED(event))
// Prevent same hotkey combination being used twice.
if (!oldname.empty()) {
auto oldlabel = TranslatableString{wxT("%s - %s")}
auto oldlabel = Verbatim( wxT("%s - %s") )
.Format(
mManager->GetCategoryFromName(oldname),
mManager->GetPrefixedLabelFromName(oldname) );
auto newlabel = TranslatableString{wxT("%s - %s")}
auto newlabel = Verbatim( wxT("%s - %s") )
.Format(
mManager->GetCategoryFromName(newname),
mManager->GetPrefixedLabelFromName(newname) );

View File

@ -119,8 +119,9 @@ void MidiIOPrefs::GetNamesAndLabels() {
const PmDeviceInfo *info = Pm_GetDeviceInfo(i);
if (info->output || info->input) { //should always happen
wxString name = wxSafeConvertMB2WX(info->interf);
if (!make_iterator_range(mHostNames).contains(TranslatableString{name})) {
mHostNames.push_back( TranslatableString{ name } );
if (!make_iterator_range(mHostNames)
.contains( Verbatim( name ) )) {
mHostNames.push_back( Verbatim( name ) );
mHostLabels.push_back(name);
}
}

View File

@ -696,7 +696,7 @@ int PrefsDialog::ShowModal()
}
else {
auto Temp = mTitlePrefix;
Temp.Join( TranslatableString{ mUniquePage->GetLabel() }, wxT(" ") );
Temp.Join( Verbatim( mUniquePage->GetLabel() ), wxT(" ") );
SetTitle(Temp);
SetName(Temp);
}

View File

@ -269,7 +269,7 @@ void ControlToolBar::RegenerateTooltips()
break;
}
std::vector<ComponentInterfaceSymbol> commands(
1u, { name, TranslatableString{ pCtrl->GetLabel() } } );
1u, { name, Verbatim( pCtrl->GetLabel() ) } );
// Some have a second
switch (iWinID)

View File

@ -386,7 +386,7 @@ void ToolBar::SetLabel(const wxString & label)
{
// Probably shouldn't reach this overload, but perhaps virtual function
// dispatch will take us here from a pointer to the wxPanel base class
mLabel = TranslatableString{ label };
mLabel = Verbatim( label );
}
void ToolBar::SetLabel(const TranslatableString & label)

View File

@ -128,40 +128,40 @@ BEGIN_POPUP_MENU(TrackMenuTable)
// functions.
OnMoveUpID,
XO("Move Track &Up").Join(
TranslatableString{
Verbatim(
CommandManager::Get( *GetActiveProject() ).
// using GET to compose menu item name for wxWidgets
GetKeyFromName(wxT("TrackMoveUp")).GET() },
GetKeyFromName(wxT("TrackMoveUp")).GET() ),
wxT("\t")
),
OnMoveTrack)
POPUP_MENU_ITEM(
OnMoveDownID,
XO("Move Track &Down").Join(
TranslatableString{
Verbatim(
CommandManager::Get( *GetActiveProject() ).
// using GET to compose menu item name for wxWidgets
GetKeyFromName(wxT("TrackMoveDown")).GET() },
GetKeyFromName(wxT("TrackMoveDown")).GET() ),
wxT("\t")
),
OnMoveTrack)
POPUP_MENU_ITEM(
OnMoveTopID,
XO("Move Track to &Top").Join(
TranslatableString{
Verbatim(
CommandManager::Get( *GetActiveProject() ).
// using GET to compose menu item name for wxWidgets
GetKeyFromName(wxT("TrackMoveTop")).GET() },
GetKeyFromName(wxT("TrackMoveTop")).GET() ),
wxT("\t")
),
OnMoveTrack)
POPUP_MENU_ITEM(
OnMoveBottomID,
XO("Move Track to &Bottom").Join(
TranslatableString{
Verbatim(
CommandManager::Get( *GetActiveProject() ).
// using GET to compose menu item name for wxWidgets
GetKeyFromName(wxT("TrackMoveBottom")).GET() },
GetKeyFromName(wxT("TrackMoveBottom")).GET() ),
wxT("\t")
),
OnMoveTrack)

View File

@ -59,9 +59,9 @@ bool XMLFileReader::Parse(XMLTagHandler *baseHandler,
// We could make a table of XOs if we wanted so that it could
// If we do, uncomment the second constructor argument so it's not
// a verbatim string
mLibraryErrorStr = TranslatableString{
mLibraryErrorStr = Verbatim(
XML_ErrorString(XML_GetErrorCode(mParser)) // , {}
};
);
mErrorStr = XO("Error: %s at line %lu").Format(
mLibraryErrorStr,