Skip to content

Commit 54e2bbd

Browse files
committed
Remove TranslatedInternalString, use ComponentInterfaceSymbol
1 parent e875ada commit 54e2bbd

19 files changed

Lines changed: 79 additions & 116 deletions

include/audacity/ComponentInterface.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,16 +78,18 @@ class ComponentInterfaceSymbol
7878

7979
// Two-argument version distinguishes internal from translatable string
8080
// such as when the first squeezes spaces out
81-
ComponentInterfaceSymbol( const wxString &internal,
81+
ComponentInterfaceSymbol( const Identifier &internal,
8282
const TranslatableString &msgid )
83-
: mInternal{ internal }
83+
: mInternal{ internal.GET() }
8484
// Do not permit non-empty msgid with empty internal
8585
, mMsgid{ internal.empty() ? TranslatableString{} : msgid }
8686
{}
8787

8888
const wxString &Internal() const { return mInternal; }
8989
const TranslatableString &Msgid() const { return mMsgid; }
9090
const wxString Translation() const { return mMsgid.Translation(); }
91+
const wxString StrippedTranslation() const
92+
{ return TranslatableString{mMsgid}.Strip().Translation(); }
9193

9294
bool empty() const { return mInternal.empty(); }
9395

src/AdornedRulerPanel.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1754,9 +1754,9 @@ void AdornedRulerPanel::DrawBothOverlays()
17541754

17551755
void AdornedRulerPanel::UpdateButtonStates()
17561756
{
1757-
auto common = [this]
1758-
(AButton &button, const CommandID &commandName, const wxString &label) {
1759-
TranslatedInternalString command{ commandName, label };
1757+
auto common = [this](
1758+
AButton &button, const CommandID &commandName, const TranslatableString &label) {
1759+
ComponentInterfaceSymbol command{ commandName, label };
17601760
ToolBar::SetButtonToolTip( *mProject, button, &command, 1u );
17611761
button.SetLabel(button.GetToolTipText());
17621762

@@ -1777,8 +1777,8 @@ void AdornedRulerPanel::UpdateButtonStates()
17771777
(gAudioIO->IsCapturing() ? 2 : 0) + (state ? 0 : 1));
17781778
// Bug 1584: Toltip now shows what clicking will do.
17791779
const auto label = state
1780-
? _("Click to unpin")
1781-
: _("Click to pin");
1780+
? XO("Click to unpin")
1781+
: XO("Click to pin");
17821782
common(*pinButton, wxT("PinnedHead"), label);
17831783
}
17841784
}

src/BatchCommandDialog.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ void MacroCommandDialog::PopulateCommandList()
143143
long ii = 0;
144144
for ( const auto &entry : mCatalog )
145145
// insert the user-facing string
146-
mChoices->InsertItem( ii++, entry.name.Translated() );
146+
mChoices->InsertItem( ii++, entry.name.StrippedTranslation() );
147147
}
148148

149149
void MacroCommandDialog::ValidateChoices()
@@ -188,11 +188,12 @@ void MacroCommandDialog::OnItemSelected(wxListEvent &event)
188188
mEditParams->Enable(!ID.empty());
189189
mUsePreset->Enable(em.HasPresets(ID));
190190

191-
if ( command.name.Translated() == mCommand->GetValue() )
191+
auto value = command.name.StrippedTranslation();
192+
if ( value == mCommand->GetValue() )
192193
// This uses the assumption of uniqueness of translated names!
193194
return;
194195

195-
mCommand->SetValue(command.name.Translated());
196+
mCommand->SetValue(value);
196197
mInternalCommandName = command.name.Internal();
197198

198199
wxString params = MacroCommands::GetCurrentParamsFor(mInternalCommandName);
@@ -244,11 +245,11 @@ void MacroCommandDialog::SetCommandAndParams(const CommandID &Command, const wxS
244245
// in default of any better friendly name
245246
mCommand->SetValue( Command.GET() );
246247
else {
247-
mCommand->SetValue( iter->name.Translated() );
248+
mCommand->SetValue( iter->name.StrippedTranslation() );
248249
// using GET to expose a CommandID to the user!
249250
// Macro command details are one place that we do expose Identifier
250251
// to (more sophisticated) users
251-
mDetails->SetValue( iter->name.Internal().GET() + "\r\n" + iter->category );
252+
mDetails->SetValue( iter->name.Internal() + "\r\n" + iter->category );
252253
mChoices->SetItemState(iter - mCatalog.begin(),
253254
wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
254255

src/BatchCommands.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ MacroCommandsCatalog::MacroCommandsCatalog( const AudacityProject *project )
294294
Entries commands;
295295
for( const auto &command : SpecialCommands )
296296
commands.push_back( {
297-
{ command.second, command.first.Translation() },
297+
{ command.second, command.first },
298298
_("Special Command")
299299
} );
300300

@@ -309,7 +309,7 @@ MacroCommandsCatalog::MacroCommandsCatalog( const AudacityProject *project )
309309
auto command = em.GetCommandIdentifier(plug->GetID());
310310
if (!command.empty())
311311
commands.push_back( {
312-
{ command, plug->GetSymbol().Translation() },
312+
{ command, plug->GetSymbol().Msgid() },
313313
plug->GetPluginType() == PluginTypeEffect ?
314314
_("Effect") : _("Menu Command (With Parameters)")
315315
} );
@@ -365,7 +365,7 @@ MacroCommandsCatalog::MacroCommandsCatalog( const AudacityProject *project )
365365
{
366366
{
367367
mNames[i], // Internal name.
368-
label.Translation() // User readable name
368+
label // User readable name
369369
},
370370
_("Menu Command (No Parameters)")
371371
}
@@ -379,23 +379,26 @@ MacroCommandsCatalog::MacroCommandsCatalog( const AudacityProject *project )
379379
// keeping specials before effects and menu items, and lastly commands.
380380
auto less =
381381
[](const Entry &a, const Entry &b)
382-
{ return a.name.Translated() < b.name.Translated(); };
382+
{ return a.name.StrippedTranslation() <
383+
b.name.StrippedTranslation(); };
383384
std::stable_sort(commands.begin(), commands.end(), less);
384385

385386
// Now uniquify by friendly name
386387
auto equal =
387388
[](const Entry &a, const Entry &b)
388-
{ return a.name.Translated() == b.name.Translated(); };
389+
{ return a.name.StrippedTranslation() ==
390+
b.name.StrippedTranslation(); };
389391
std::unique_copy(
390392
commands.begin(), commands.end(), std::back_inserter(mCommands), equal);
391393
}
392394

393395
// binary search
394-
auto MacroCommandsCatalog::ByFriendlyName( const wxString &friendlyName ) const
396+
auto MacroCommandsCatalog::ByFriendlyName( const TranslatableString &friendlyName ) const
395397
-> Entries::const_iterator
396398
{
397399
const auto less = [](const Entry &entryA, const Entry &entryB)
398-
{ return entryA.name.Translated() < entryB.name.Translated(); };
400+
{ return entryA.name.StrippedTranslation() <
401+
entryB.name.StrippedTranslation(); };
399402
auto range = std::equal_range(
400403
begin(), end(), Entry{ { {}, friendlyName }, {} }, less
401404
);
@@ -943,7 +946,7 @@ bool MacroCommands::ApplyMacro(
943946
// uh oh, using GET to expose an internal name to the user!
944947
// in default of any better friendly name
945948
command.GET()
946-
: iter->name.Translated();
949+
: iter->name.StrippedTranslation();
947950
if (!ApplyCommandInBatchMode(friendly, command, mParamsMacro[i]) || mAbort)
948951
break;
949952
}

src/BatchCommands.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include "export/Export.h"
1818
#include "commands/CommandFlag.h"
19+
#include "audacity/ComponentInterface.h" // for ComponentInterfaceSymbol
1920

2021
class wxArrayString;
2122
class Effect;
@@ -28,15 +29,15 @@ class MacroCommandsCatalog {
2829
public:
2930
// A triple of user-visible name, internal string identifier and type/help string.
3031
struct Entry {
31-
TranslatedInternalString name;
32+
ComponentInterfaceSymbol name;
3233
wxString category;
3334
};
3435
using Entries = std::vector<Entry>;
3536

3637
MacroCommandsCatalog( const AudacityProject *project );
3738

3839
// binary search
39-
Entries::const_iterator ByFriendlyName( const wxString &friendlyName ) const;
40+
Entries::const_iterator ByFriendlyName( const TranslatableString &friendlyName ) const;
4041
// linear search
4142
Entries::const_iterator ByCommandId( const CommandID &commandId ) const;
4243

src/BatchProcessDialog.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,7 @@ void MacrosWindow::AddItem(const CommandID &Action, const wxString &Params)
745745
{
746746
auto entry = mCatalog.ByCommandId(Action);
747747
auto friendlyName = entry != mCatalog.end()
748-
? entry->name.Translated()
748+
? entry->name.StrippedTranslation()
749749
:
750750
// uh oh, using GET to expose an internal name to the user!
751751
// in default of any better friendly name

src/Internat.h

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -163,43 +163,4 @@ class ComponentInterfaceSymbol;
163163
wxArrayStringEx LocalizedStrings(
164164
const EnumValueSymbol strings[], size_t nStrings);
165165

166-
// This object pairs an internal string, maybe empty, with a translated string.
167-
// Any internal string may be written to configuration or other files and,
168-
// for compatibility, should not vary between Audacity versions.
169-
// The translated string may be shown to users and may vary with locale, and
170-
// Audacity version if it is decided to use a different user-visible message.
171-
// Sometimes the translated string is derived from a msgid identical
172-
// to the internal string. The translated string is not meant to persist.
173-
class TranslatedInternalString
174-
{
175-
public:
176-
177-
using ID = CommandID;
178-
179-
TranslatedInternalString() = default;
180-
181-
// One-argument constructor from a msgid
182-
explicit TranslatedInternalString( const wxString &internal )
183-
: mInternal{ internal }, mTranslated{ GetCustomTranslation( internal ) }
184-
{}
185-
186-
// Two-argument version, when translated does not derive from internal
187-
TranslatedInternalString( const ID &internal,
188-
const wxString &translated )
189-
: mInternal{ internal }, mTranslated{ translated }
190-
{}
191-
192-
const ID &Internal() const { return mInternal; }
193-
const wxString Translated() const
194-
{
195-
wxString Temp = mTranslated;
196-
Temp.Replace( "&","" );
197-
return Temp;
198-
}
199-
200-
private:
201-
ID mInternal;
202-
wxString mTranslated;
203-
};
204-
205166
#endif

src/commands/BatchEvalCommand.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ bool BatchEvalCommand::Apply(const CommandContext & context)
6464
auto iter = catalog.ByCommandId(cmdName);
6565
const wxString &friendly = (iter == catalog.end())
6666
? cmdName // Expose internal name to user, in default of a better one!
67-
: iter->name.Translated();
67+
: iter->name.StrippedTranslation();
6868

6969
// Create a Batch that will have just one command in it...
7070
MacroCommands Batch;

src/commands/CommandManager.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -963,8 +963,8 @@ void CommandManager::SetKeyFromIndex(int i, const NormalizedKeyString &key)
963963
entry->key = key;
964964
}
965965

966-
wxString CommandManager::DescribeCommandsAndShortcuts
967-
(const TranslatedInternalString commands[], size_t nCommands) const
966+
TranslatableString CommandManager::DescribeCommandsAndShortcuts(
967+
const ComponentInterfaceSymbol commands[], size_t nCommands) const
968968
{
969969
wxString mark;
970970
// This depends on the language setting and may change in-session after
@@ -974,15 +974,19 @@ wxString CommandManager::DescribeCommandsAndShortcuts
974974
mark = wxT("\u200f");
975975

976976
static const wxString &separatorFormat = wxT("%s / %s");
977-
wxString result;
977+
TranslatableString result;
978978
for (size_t ii = 0; ii < nCommands; ++ii) {
979979
const auto &pair = commands[ii];
980980
// If RTL, then the control character forces right-to-left sequencing of
981981
// "/" -separated command names, and puts any "(...)" shortcuts to the
982982
// left, consistently with accelerators in menus (assuming matching
983983
// operating system prefernces for language), even if the command name
984984
// was missing from the translation file and defaulted to the English.
985-
auto piece = wxString::Format(wxT("%s%s"), mark, pair.Translated());
985+
986+
// Note: not putting this and other short format strings in the
987+
// translation catalogs
988+
auto piece = TranslatableString{wxT("%s%s")}
989+
.Format( mark, TranslatableString{pair.Msgid()}.Strip() );
986990

987991
auto name = pair.Internal();
988992
if (!name.empty()) {
@@ -1000,14 +1004,14 @@ wxString CommandManager::DescribeCommandsAndShortcuts
10001004
#endif
10011005
// The mark makes correctly placed parentheses for RTL, even
10021006
// in the case that the piece is untranslated.
1003-
piece = wxString::Format(format, piece, mark, keyString);
1007+
piece = TranslatableString{format}.Format( piece, mark, keyString );
10041008
}
10051009
}
10061010

10071011
if (result.empty())
10081012
result = piece;
10091013
else
1010-
result = wxString::Format(separatorFormat, result, piece);
1014+
result = TranslatableString{ separatorFormat }.Format( result, piece );
10111015
}
10121016
return result;
10131017
}

src/commands/CommandManager.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ class wxMenuBar;
3434
class wxArrayString;
3535
class wxMenu;
3636
class wxMenuBar;
37-
class TranslatedInternalString;
3837
using CommandParameter = CommandID;
3938

4039
struct MenuBarListEntry
@@ -288,11 +287,11 @@ class AUDACITY_DLL_API CommandManager final
288287
///
289288
/// Formatting summaries that include shortcut keys
290289
///
291-
wxString DescribeCommandsAndShortcuts
290+
TranslatableString DescribeCommandsAndShortcuts
292291
(
293292
// If a shortcut key is defined for the command, then it is appended,
294293
// parenthesized, after the translated name.
295-
const TranslatedInternalString commands[], size_t nCommands) const;
294+
const ComponentInterfaceSymbol commands[], size_t nCommands) const;
296295

297296
// Sorted list of the shortcut keys to be exluded from the standard defaults
298297
static const std::vector<NormalizedKeyString> &ExcludedList();

0 commit comments

Comments
 (0)