1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-06-25 16:48:44 +02:00

Reviewed whether fields of PluginDescriptor are translated or not...

... Threw away one field as unused; found a subtle but inconsequential mistake
in the use of another.

Fields that are stored for the purpose of internal identifiers should be
untranslated.  Strings used to form registry keys should certainly be
untranslated.  Translations should only happen for purposes of display to
the user.
This commit is contained in:
Paul Licameli 2018-01-05 18:40:18 -05:00
commit 0badd25844
3 changed files with 80 additions and 64 deletions

View File

@ -171,8 +171,8 @@ enum {
WX_DEFINE_ARRAY_PTR(const PluginDescriptor *, EffectPlugs); WX_DEFINE_ARRAY_PTR(const PluginDescriptor *, EffectPlugs);
static int SortEffectsByName(const PluginDescriptor **a, const PluginDescriptor **b) static int SortEffectsByName(const PluginDescriptor **a, const PluginDescriptor **b)
{ {
wxString akey = (*a)->GetName(); wxString akey = (*a)->GetTranslatedName();
wxString bkey = (*b)->GetName(); wxString bkey = (*b)->GetTranslatedName();
akey += (*a)->GetPath(); akey += (*a)->GetPath();
bkey += (*b)->GetPath(); bkey += (*b)->GetPath();
@ -182,8 +182,8 @@ static int SortEffectsByName(const PluginDescriptor **a, const PluginDescriptor
static int SortEffectsByPublisher(const PluginDescriptor **a, const PluginDescriptor **b) static int SortEffectsByPublisher(const PluginDescriptor **a, const PluginDescriptor **b)
{ {
wxString akey = (*a)->GetVendor(); wxString akey = (*a)->GetTranslatedVendor();
wxString bkey = (*b)->GetVendor(); wxString bkey = (*b)->GetTranslatedVendor();
if (akey.IsEmpty()) if (akey.IsEmpty())
{ {
@ -194,8 +194,8 @@ static int SortEffectsByPublisher(const PluginDescriptor **a, const PluginDescri
bkey = _("Uncategorized"); bkey = _("Uncategorized");
} }
akey += (*a)->GetName(); akey += (*a)->GetTranslatedName();
bkey += (*b)->GetName(); bkey += (*b)->GetTranslatedName();
akey += (*a)->GetPath(); akey += (*a)->GetPath();
bkey += (*b)->GetPath(); bkey += (*b)->GetPath();
@ -205,8 +205,8 @@ static int SortEffectsByPublisher(const PluginDescriptor **a, const PluginDescri
static int SortEffectsByPublisherAndName(const PluginDescriptor **a, const PluginDescriptor **b) static int SortEffectsByPublisherAndName(const PluginDescriptor **a, const PluginDescriptor **b)
{ {
wxString akey = (*a)->GetVendor(); wxString akey = (*a)->GetTranslatedVendor();
wxString bkey = (*b)->GetVendor(); wxString bkey = (*b)->GetTranslatedVendor();
if ((*a)->IsEffectDefault()) if ((*a)->IsEffectDefault())
{ {
@ -217,8 +217,8 @@ static int SortEffectsByPublisherAndName(const PluginDescriptor **a, const Plugi
bkey = wxEmptyString; bkey = wxEmptyString;
} }
akey += (*a)->GetName(); akey += (*a)->GetTranslatedName();
bkey += (*b)->GetName(); bkey += (*b)->GetTranslatedName();
akey += (*a)->GetPath(); akey += (*a)->GetPath();
bkey += (*b)->GetPath(); bkey += (*b)->GetPath();
@ -228,8 +228,8 @@ static int SortEffectsByPublisherAndName(const PluginDescriptor **a, const Plugi
static int SortEffectsByTypeAndName(const PluginDescriptor **a, const PluginDescriptor **b) static int SortEffectsByTypeAndName(const PluginDescriptor **a, const PluginDescriptor **b)
{ {
wxString akey = (*a)->GetEffectFamily(); wxString akey = (*a)->GetTranslatedEffectFamily();
wxString bkey = (*b)->GetEffectFamily(); wxString bkey = (*b)->GetTranslatedEffectFamily();
if (akey.IsEmpty()) if (akey.IsEmpty())
{ {
@ -249,8 +249,8 @@ static int SortEffectsByTypeAndName(const PluginDescriptor **a, const PluginDesc
bkey = wxEmptyString; bkey = wxEmptyString;
} }
akey += (*a)->GetName(); akey += (*a)->GetTranslatedName();
bkey += (*b)->GetName(); bkey += (*b)->GetTranslatedName();
akey += (*a)->GetPath(); akey += (*a)->GetPath();
bkey += (*b)->GetPath(); bkey += (*b)->GetPath();
@ -260,8 +260,8 @@ static int SortEffectsByTypeAndName(const PluginDescriptor **a, const PluginDesc
static int SortEffectsByType(const PluginDescriptor **a, const PluginDescriptor **b) static int SortEffectsByType(const PluginDescriptor **a, const PluginDescriptor **b)
{ {
wxString akey = (*a)->GetEffectFamily(); wxString akey = (*a)->GetTranslatedEffectFamily();
wxString bkey = (*b)->GetEffectFamily(); wxString bkey = (*b)->GetTranslatedEffectFamily();
if (akey.IsEmpty()) if (akey.IsEmpty())
{ {
@ -272,8 +272,8 @@ static int SortEffectsByType(const PluginDescriptor **a, const PluginDescriptor
bkey = _("Uncategorized"); bkey = _("Uncategorized");
} }
akey += (*a)->GetName(); akey += (*a)->GetTranslatedName();
bkey += (*b)->GetName(); bkey += (*b)->GetTranslatedName();
akey += (*a)->GetPath(); akey += (*a)->GetPath();
bkey += (*b)->GetPath(); bkey += (*b)->GetPath();
@ -1711,7 +1711,7 @@ void AudacityProject::AddEffectMenuItems(CommandManager *c,
{ {
const PluginDescriptor *plug = plugs[i]; const PluginDescriptor *plug = plugs[i];
wxString name = plug->GetName(); wxString name = plug->GetTranslatedName();
if (plug->IsEffectInteractive()) if (plug->IsEffectInteractive())
{ {
@ -1720,7 +1720,7 @@ void AudacityProject::AddEffectMenuItems(CommandManager *c,
if (groupBy == wxT("groupby:publisher")) if (groupBy == wxT("groupby:publisher"))
{ {
current = plug->GetVendor(); current = plug->GetTranslatedVendor();
if (current.IsEmpty()) if (current.IsEmpty())
{ {
current = _("Unknown"); current = _("Unknown");
@ -1728,7 +1728,7 @@ void AudacityProject::AddEffectMenuItems(CommandManager *c,
} }
else if (groupBy == wxT("groupby:type")) else if (groupBy == wxT("groupby:type"))
{ {
current = plug->GetEffectFamily(); current = plug->GetTranslatedEffectFamily();
if (current.IsEmpty()) if (current.IsEmpty())
{ {
current = _("Unknown"); current = _("Unknown");
@ -1775,7 +1775,7 @@ void AudacityProject::AddEffectMenuItems(CommandManager *c,
{ {
const PluginDescriptor *plug = plugs[i]; const PluginDescriptor *plug = plugs[i];
wxString name = plug->GetName(); wxString name = plug->GetTranslatedName();
if (plug->IsEffectInteractive()) if (plug->IsEffectInteractive())
{ {
@ -1785,11 +1785,11 @@ void AudacityProject::AddEffectMenuItems(CommandManager *c,
wxString group = wxEmptyString; wxString group = wxEmptyString;
if (groupBy == wxT("sortby:publisher:name")) if (groupBy == wxT("sortby:publisher:name"))
{ {
group = plug->GetVendor(); group = plug->GetTranslatedVendor();
} }
else if (groupBy == wxT("sortby:type:name")) else if (groupBy == wxT("sortby:type:name"))
{ {
group = plug->GetEffectFamily(); group = plug->GetTranslatedEffectFamily();
} }
if (plug->IsEffectDefault()) if (plug->IsEffectDefault())

View File

@ -628,7 +628,7 @@ void PluginRegistrationDialog::PopulateOrExchange(ShuttleGui &S)
if (plugType == PluginTypeEffect) if (plugType == PluginTypeEffect)
{ {
item.name = plug.GetName(); item.name = plug.GetTranslatedName();
} }
// This is not right and will not work when other plugin types are added. // This is not right and will not work when other plugin types are added.
// But it's presumed that the plugin manager dialog will be fully developed // But it's presumed that the plugin manager dialog will be fully developed
@ -1145,24 +1145,29 @@ const wxString & PluginDescriptor::GetSymbol() const
return mSymbol; return mSymbol;
} }
wxString PluginDescriptor::GetName(bool translate) const wxString PluginDescriptor::GetUntranslatedName() const
{ {
return translate ? wxString(wxGetTranslation(mName)) : mName; return mName;
} }
wxString PluginDescriptor::GetVersion(bool translate) const wxString PluginDescriptor::GetUntranslatedVersion() const
{ {
return translate ? wxString(wxGetTranslation(mVersion)) : mVersion; return mVersion;
} }
wxString PluginDescriptor::GetVendor(bool translate) const wxString PluginDescriptor::GetTranslatedName() const
{ {
return translate ? wxString(wxGetTranslation(mVendor)) : mVendor; return wxGetTranslation(mName);
} }
wxString PluginDescriptor::GetDescription(bool translate) const wxString PluginDescriptor::GetUntranslatedVendor() const
{ {
return translate ? wxString(wxGetTranslation(mDescription)) : mDescription; return mVendor;
}
wxString PluginDescriptor::GetTranslatedVendor() const
{
return wxGetTranslation(mVendor);
} }
bool PluginDescriptor::IsEnabled() const bool PluginDescriptor::IsEnabled() const
@ -1215,11 +1220,6 @@ void PluginDescriptor::SetVendor(const wxString & vendor)
mVendor = vendor; mVendor = vendor;
} }
void PluginDescriptor::SetDescription(const wxString & description)
{
mDescription = description;
}
void PluginDescriptor::SetEnabled(bool enable) void PluginDescriptor::SetEnabled(bool enable)
{ {
mEnabled = enable; mEnabled = enable;
@ -1232,9 +1232,14 @@ void PluginDescriptor::SetValid(bool valid)
// Effects // Effects
wxString PluginDescriptor::GetEffectFamily(bool translate) const wxString PluginDescriptor::GetUntranslatedEffectFamily() const
{ {
return translate ? wxString(wxGetTranslation(mEffectFamily)) : mEffectFamily; return mEffectFamily;
}
wxString PluginDescriptor::GetTranslatedEffectFamily() const
{
return wxGetTranslation(mEffectFamily);
} }
EffectType PluginDescriptor::GetEffectType() const EffectType PluginDescriptor::GetEffectType() const
@ -1997,7 +2002,7 @@ void PluginManager::LoadGroup(wxFileConfig *pRegistry, PluginType type)
// Get the symbol...use name if not found // Get the symbol...use name if not found
if (!pRegistry->Read(KEY_SYMBOL, &strVal)) if (!pRegistry->Read(KEY_SYMBOL, &strVal))
{ {
strVal = plug.GetName(); strVal = plug.GetTranslatedName();
} }
plug.SetSymbol(strVal); plug.SetSymbol(strVal);
@ -2015,12 +2020,18 @@ void PluginManager::LoadGroup(wxFileConfig *pRegistry, PluginType type)
} }
plug.SetVendor(strVal); plug.SetVendor(strVal);
#if 0
// This was done before version 2.2.2, but the value was not really used
// But absence of a value will cause early versions to skip the group
// Therefore we still write a blank to keep pluginregistry.cfg
// backwards-compatible
// Get the description and bypass group if not found // Get the description and bypass group if not found
if (!pRegistry->Read(KEY_DESCRIPTION, &strVal)) if (!pRegistry->Read(KEY_DESCRIPTION, &strVal))
{ {
continue; continue;
} }
plug.SetDescription(strVal); #endif
// Is it enabled...default to no if not found // Is it enabled...default to no if not found
pRegistry->Read(KEY_ENABLED, &boolVal, false); pRegistry->Read(KEY_ENABLED, &boolVal, false);
@ -2209,10 +2220,11 @@ void PluginManager::SaveGroup(wxFileConfig *pRegistry, PluginType type)
pRegistry->Write(KEY_PATH, plug.GetPath()); pRegistry->Write(KEY_PATH, plug.GetPath());
pRegistry->Write(KEY_SYMBOL, plug.GetSymbol()); pRegistry->Write(KEY_SYMBOL, plug.GetSymbol());
pRegistry->Write(KEY_NAME, plug.GetName(false)); pRegistry->Write(KEY_NAME, plug.GetUntranslatedName());
pRegistry->Write(KEY_VERSION, plug.GetVersion(false)); pRegistry->Write(KEY_VERSION, plug.GetUntranslatedVersion());
pRegistry->Write(KEY_VENDOR, plug.GetVendor(false)); pRegistry->Write(KEY_VENDOR, plug.GetUntranslatedVendor());
pRegistry->Write(KEY_DESCRIPTION, plug.GetDescription(false)); // Write a blank -- see comments in LoadGroup:
pRegistry->Write(KEY_DESCRIPTION, wxString{});
pRegistry->Write(KEY_PROVIDERID, plug.GetProviderID()); pRegistry->Write(KEY_PROVIDERID, plug.GetProviderID());
pRegistry->Write(KEY_ENABLED, plug.IsEnabled()); pRegistry->Write(KEY_ENABLED, plug.IsEnabled());
pRegistry->Write(KEY_VALID, plug.IsValid()); pRegistry->Write(KEY_VALID, plug.IsValid());
@ -2247,7 +2259,7 @@ void PluginManager::SaveGroup(wxFileConfig *pRegistry, PluginType type)
stype = KEY_EFFECTTYPE_HIDDEN; stype = KEY_EFFECTTYPE_HIDDEN;
} }
pRegistry->Write(KEY_EFFECTTYPE, stype); pRegistry->Write(KEY_EFFECTTYPE, stype);
pRegistry->Write(KEY_EFFECTFAMILY, plug.GetEffectFamily(false)); pRegistry->Write(KEY_EFFECTFAMILY, plug.GetUntranslatedEffectFamily());
pRegistry->Write(KEY_EFFECTDEFAULT, plug.IsEffectDefault()); pRegistry->Write(KEY_EFFECTDEFAULT, plug.IsEffectDefault());
pRegistry->Write(KEY_EFFECTINTERACTIVE, plug.IsEffectInteractive()); pRegistry->Write(KEY_EFFECTINTERACTIVE, plug.IsEffectInteractive());
pRegistry->Write(KEY_EFFECTREALTIME, plug.IsEffectRealtime()); pRegistry->Write(KEY_EFFECTREALTIME, plug.IsEffectRealtime());
@ -2445,7 +2457,8 @@ const PluginDescriptor *PluginManager::GetFirstPlugin(PluginType type)
bool familyEnabled = true; bool familyEnabled = true;
if (type == PluginTypeEffect) if (type == PluginTypeEffect)
{ {
gPrefs->Read(plug.GetEffectFamily() + wxT("/Enable"), &familyEnabled, true); // This preference may be written by EffectsPrefs
gPrefs->Read(plug.GetUntranslatedEffectFamily() + wxT("/Enable"), &familyEnabled, true);
} }
if (plug.IsValid() && plug.IsEnabled() && plug.GetPluginType() == type && familyEnabled) if (plug.IsValid() && plug.IsEnabled() && plug.GetPluginType() == type && familyEnabled)
{ {
@ -2464,7 +2477,8 @@ const PluginDescriptor *PluginManager::GetNextPlugin(PluginType type)
bool familyEnabled = true; bool familyEnabled = true;
if (type == PluginTypeEffect) if (type == PluginTypeEffect)
{ {
gPrefs->Read(plug.GetEffectFamily() + wxT("/Enable"), &familyEnabled, true); // This preference may be written by EffectsPrefs
gPrefs->Read(plug.GetUntranslatedEffectFamily() + wxT("/Enable"), &familyEnabled, true);
} }
if (plug.IsValid() && plug.IsEnabled() && plug.GetPluginType() == type && familyEnabled) if (plug.IsValid() && plug.IsEnabled() && plug.GetPluginType() == type && familyEnabled)
{ {
@ -2484,7 +2498,8 @@ const PluginDescriptor *PluginManager::GetFirstPluginForEffectType(EffectType ty
PluginDescriptor & plug = mPluginsIter->second; PluginDescriptor & plug = mPluginsIter->second;
bool familyEnabled; bool familyEnabled;
gPrefs->Read(plug.GetEffectFamily(false) + wxT("/Enable"), &familyEnabled, true); // This preference may be written by EffectsPrefs
gPrefs->Read(plug.GetUntranslatedEffectFamily() + wxT("/Enable"), &familyEnabled, true);
if (plug.IsValid() && plug.IsEnabled() && plug.GetEffectType() == type && familyEnabled) if (plug.IsValid() && plug.IsEnabled() && plug.GetEffectType() == type && familyEnabled)
{ {
if (plug.IsInstantiated() && em.IsHidden(plug.GetID())) if (plug.IsInstantiated() && em.IsHidden(plug.GetID()))
@ -2507,7 +2522,8 @@ const PluginDescriptor *PluginManager::GetNextPluginForEffectType(EffectType typ
{ {
PluginDescriptor & plug = mPluginsIter->second; PluginDescriptor & plug = mPluginsIter->second;
bool familyEnabled; bool familyEnabled;
gPrefs->Read(plug.GetEffectFamily() + wxT("/Enable"), &familyEnabled, true); // This preference may be written by EffectsPrefs
gPrefs->Read(plug.GetUntranslatedEffectFamily() + wxT("/Enable"), &familyEnabled, true);
if (plug.IsValid() && plug.IsEnabled() && plug.GetEffectType() == type && familyEnabled) if (plug.IsValid() && plug.IsEnabled() && plug.GetEffectType() == type && familyEnabled)
{ {
if (plug.IsInstantiated() && em.IsHidden(plug.GetID())) if (plug.IsInstantiated() && em.IsHidden(plug.GetID()))
@ -2560,7 +2576,7 @@ wxString PluginManager::GetName(const PluginID & ID)
return wxEmptyString; return wxEmptyString;
} }
return mPlugins[ID].GetName(); return mPlugins[ID].GetTranslatedName();
} }
IdentInterface *PluginManager::GetInstance(const PluginID & ID) IdentInterface *PluginManager::GetInstance(const PluginID & ID)
@ -2660,7 +2676,6 @@ PluginDescriptor & PluginManager::CreatePlugin(const PluginID & id,
plug.SetName(ident->GetName()); plug.SetName(ident->GetName());
plug.SetVendor(ident->GetVendor()); plug.SetVendor(ident->GetVendor());
plug.SetVersion(ident->GetVersion()); plug.SetVersion(ident->GetVersion());
plug.SetDescription(ident->GetDescription());
return plug; return plug;
} }
@ -2897,9 +2912,9 @@ wxString PluginManager::SettingsPath(const PluginID & ID, bool shared)
wxString id = GetPluginTypeString(plug.GetPluginType()) + wxString id = GetPluginTypeString(plug.GetPluginType()) +
wxT("_") + wxT("_") +
plug.GetEffectFamily(false) + // is empty for non-Effects plug.GetUntranslatedEffectFamily() + // is empty for non-Effects
wxT("_") + wxT("_") +
plug.GetVendor(false) + plug.GetUntranslatedVendor() +
wxT("_") + wxT("_") +
(shared ? wxT("") : plug.GetSymbol()); (shared ? wxT("") : plug.GetSymbol());

View File

@ -62,11 +62,14 @@ public:
const wxString & GetPath() const; const wxString & GetPath() const;
const wxString & GetSymbol() const; const wxString & GetSymbol() const;
// These return translated strings (if available and if requested) wxString GetUntranslatedVersion() const;
wxString GetName(bool translate = true) const; // There is no translated version
wxString GetVersion(bool translate = true) const;
wxString GetVendor(bool translate = true) const; wxString GetUntranslatedName() const;
wxString GetDescription(bool translate = true) const; wxString GetTranslatedName() const;
wxString GetUntranslatedVendor() const;
wxString GetTranslatedVendor() const;
bool IsEnabled() const; bool IsEnabled() const;
bool IsValid() const; bool IsValid() const;
@ -81,15 +84,14 @@ public:
void SetName(const wxString & name); void SetName(const wxString & name);
void SetVersion(const wxString & version); void SetVersion(const wxString & version);
void SetVendor(const wxString & vendor); void SetVendor(const wxString & vendor);
void SetDescription(const wxString & description);
void SetEnabled(bool enable); void SetEnabled(bool enable);
void SetValid(bool valid); void SetValid(bool valid);
// Effect plugins only // Effect plugins only
// Will return an untranslated string wxString GetUntranslatedEffectFamily() const;
wxString GetEffectFamily(bool translate = true) const; wxString GetTranslatedEffectFamily() const;
EffectType GetEffectType() const; EffectType GetEffectType() const;
bool IsEffectDefault() const; bool IsEffectDefault() const;
bool IsEffectInteractive() const; bool IsEffectInteractive() const;
@ -135,7 +137,6 @@ private:
wxString mName; wxString mName;
wxString mVersion; wxString mVersion;
wxString mVendor; wxString mVendor;
wxString mDescription;
wxString mProviderID; wxString mProviderID;
bool mEnabled; bool mEnabled;
bool mValid; bool mValid;