mirror of
https://github.com/cookiengineer/audacity
synced 2025-10-20 17:41:13 +02:00
Define TranslatableString::Strip()
This commit is contained in:
@@ -455,6 +455,18 @@ public:
|
|||||||
return PluralTemp< N >{ *this, pluralStr };
|
return PluralTemp< N >{ *this, pluralStr };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Translated strings may still contain menu hot-key codes (indicated by &)
|
||||||
|
// that wxWidgets interprets, and also trailing ellipses, that should be
|
||||||
|
// removed for other uses.
|
||||||
|
enum StripOptions : unsigned {
|
||||||
|
// Values to be combined with bitwise OR
|
||||||
|
MenuCodes = 0x1,
|
||||||
|
Ellipses = 0x2,
|
||||||
|
};
|
||||||
|
TranslatableString &Strip( unsigned options = MenuCodes ) &;
|
||||||
|
TranslatableString &&Strip( unsigned options = MenuCodes ) &&
|
||||||
|
{ return std::move( Strip( options ) ); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
enum class Request {
|
enum class Request {
|
||||||
Context, // return a disambiguating context string
|
Context, // return a disambiguating context string
|
||||||
|
@@ -312,6 +312,37 @@ bool TranslatableString::IsVerbatim() const
|
|||||||
return DoGetContext( mFormatter ) == NullContextName;
|
return DoGetContext( mFormatter ) == NullContextName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TranslatableString &TranslatableString::Strip( unsigned codes ) &
|
||||||
|
{
|
||||||
|
auto prevFormatter = mFormatter;
|
||||||
|
mFormatter = [prevFormatter, codes]
|
||||||
|
( const wxString & str, TranslatableString::Request request ) -> wxString {
|
||||||
|
switch ( request ) {
|
||||||
|
case Request::Context:
|
||||||
|
return TranslatableString::DoGetContext( prevFormatter );
|
||||||
|
case Request::Format:
|
||||||
|
case Request::DebugFormat:
|
||||||
|
default: {
|
||||||
|
bool debug = request == Request::DebugFormat;
|
||||||
|
auto result =
|
||||||
|
TranslatableString::DoSubstitute( prevFormatter, str, debug );
|
||||||
|
if ( codes & MenuCodes )
|
||||||
|
result = wxStripMenuCodes( result );
|
||||||
|
if ( codes & Ellipses ) {
|
||||||
|
if (result.EndsWith(wxT("...")))
|
||||||
|
result = result.Left( result.length() - 3 );
|
||||||
|
// Also check for the single-character Unicode ellipsis
|
||||||
|
else if (result.EndsWith(wxT("\u2026")))
|
||||||
|
result = result.Left( result.length() - 1 );
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
wxString TranslatableString::DoGetContext( const Formatter &formatter )
|
wxString TranslatableString::DoGetContext( const Formatter &formatter )
|
||||||
{
|
{
|
||||||
return formatter ? formatter( {}, Request::Context ) : wxString{};
|
return formatter ? formatter( {}, Request::Context ) : wxString{};
|
||||||
|
@@ -2091,7 +2091,7 @@ void ShuttleGuiBase::UpdateSizersCore(bool bPrepend, int Flags, bool prompt)
|
|||||||
mpWind->SetToolTip( mItem.mToolTip.Translation() );
|
mpWind->SetToolTip( mItem.mToolTip.Translation() );
|
||||||
|
|
||||||
if ( !mItem.mName.empty() )
|
if ( !mItem.mName.empty() )
|
||||||
mpWind->SetName( wxStripMenuCodes( mItem.mName.Translation() ) );
|
mpWind->SetName( mItem.mName.Strip().Translation() );
|
||||||
|
|
||||||
if ( !mItem.mNameSuffix.empty() )
|
if ( !mItem.mNameSuffix.empty() )
|
||||||
mpWind->SetName(
|
mpWind->SetName(
|
||||||
|
Reference in New Issue
Block a user