1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-09-18 09:00:52 +02:00

Issue 887: Some strings didn't translate, though in catalogs...

... What they had in common was the use of the XC macro to specify a
disambiguating context string.  Example: "Interface" page of preferences.

TranslatableString had not implemented this
correctly except in the less usual case of plurals.
This commit is contained in:
Paul Licameli 2021-05-12 23:50:49 -04:00 committed by James Crook
parent 5b77d19324
commit 9e70fa71ba
2 changed files with 22 additions and 9 deletions

View File

@ -373,7 +373,10 @@ public:
default: {
bool debug = request == Request::DebugFormat;
return wxString::Format(
TranslatableString::DoSubstitute( prevFormatter, str, debug ),
TranslatableString::DoSubstitute(
prevFormatter,
str, TranslatableString::DoGetContext( prevFormatter ),
debug ),
TranslatableString::TranslateArgument( args, debug )...
);
}
@ -399,8 +402,11 @@ public:
switch ( request ) {
case Request::Context:
return context;
case Request::DebugFormat:
return DoSubstitute( {}, str, context, true );
case Request::Format:
default:
return str;
return DoSubstitute( {}, str, context, false );
}
};
return *this;
@ -477,9 +483,11 @@ private:
static wxString DoGetContext( const Formatter &formatter );
static wxString DoSubstitute(
const Formatter &formatter, const wxString &format, bool debug );
const Formatter &formatter,
const wxString &format, const wxString &context, bool debug );
wxString DoFormat( bool debug ) const
{ return DoSubstitute( mFormatter, mMsgid, debug ); }
{ return DoSubstitute(
mFormatter, mMsgid, DoGetContext(mFormatter), debug ); }
static wxString DoChooseFormat(
const Formatter &formatter,

View File

@ -334,7 +334,10 @@ TranslatableString &TranslatableString::Strip( unsigned codes ) &
default: {
bool debug = request == Request::DebugFormat;
auto result =
TranslatableString::DoSubstitute( prevFormatter, str, debug );
TranslatableString::DoSubstitute(
prevFormatter,
str, TranslatableString::DoGetContext( prevFormatter ),
debug );
if ( codes & MenuCodes )
result = wxStripMenuCodes( result );
if ( codes & Ellipses ) {
@ -357,13 +360,13 @@ wxString TranslatableString::DoGetContext( const Formatter &formatter )
return formatter ? formatter( {}, Request::Context ) : wxString{};
}
wxString TranslatableString::DoSubstitute(
const Formatter &formatter, const wxString &format, bool debug )
wxString TranslatableString::DoSubstitute( const Formatter &formatter,
const wxString &format, const wxString &context, bool debug )
{
return formatter
? formatter( format, debug ? Request::DebugFormat : Request::Format )
: // come here for most translatable strings, which have no formatting
( debug ? format : wxGetTranslation( format ) );
( debug ? format : wxGetTranslation( format, wxString{}, context ) );
}
wxString TranslatableString::DoChooseFormat(
@ -404,7 +407,9 @@ TranslatableString &TranslatableString::Join(
default: {
bool debug = request == Request::DebugFormat;
return
TranslatableString::DoSubstitute( prevFormatter, str, debug )
TranslatableString::DoSubstitute( prevFormatter,
str, TranslatableString::DoGetContext( prevFormatter ),
debug )
+ separator
+ arg.DoFormat( debug );
}