mirror of
https://github.com/cookiengineer/audacity
synced 2025-05-01 16:19:43 +02:00
TranslatableString has + and +=, and translation of Format arguments
This commit is contained in:
parent
d63b5b4bfa
commit
94fc1bb2a8
@ -348,9 +348,11 @@ public:
|
||||
// Returns true if context is NullContextFormatter
|
||||
bool IsVerbatim() const;
|
||||
|
||||
// Capture variadic format arguments (by copy). The subsitution is
|
||||
// Capture variadic format arguments (by copy). The substitution is
|
||||
// computed later in a call to Translate() after msgid is looked up in the
|
||||
// translation catalog.
|
||||
// Any format arguments that are also of type TranslatableString will be
|
||||
// translated too at substitution time
|
||||
template <typename... Args>
|
||||
TranslatableString&& Format( Args&&... args ) &&
|
||||
{
|
||||
@ -361,17 +363,34 @@ public:
|
||||
if (str.empty())
|
||||
return context;
|
||||
else
|
||||
return wxString::Format( str, args... );
|
||||
return wxString::Format(
|
||||
str, TranslatableString::TranslateArgument(args)... );
|
||||
};
|
||||
return std::move( *this );
|
||||
}
|
||||
|
||||
// Append another translatable string; lookup of msgids for
|
||||
// this and for the argument are both delayed until Translate() is invoked
|
||||
// on this, and then the formatter concatenates the translations
|
||||
TranslatableString &operator +=( const TranslatableString &arg );
|
||||
|
||||
friend std::hash< TranslatableString >;
|
||||
private:
|
||||
|
||||
template< typename T > static const T &TranslateArgument( const T &arg )
|
||||
{ return arg; }
|
||||
static wxString TranslateArgument ( const TranslatableString &arg )
|
||||
{ return arg.Translation(); }
|
||||
|
||||
Formatter mFormatter;
|
||||
};
|
||||
|
||||
inline TranslatableString operator +(
|
||||
const TranslatableString &x, const TranslatableString &y )
|
||||
{
|
||||
return TranslatableString{ x } += y;
|
||||
}
|
||||
|
||||
using TranslatableStrings = std::vector<TranslatableString>;
|
||||
|
||||
// For using std::unordered_map on TranslatableString
|
||||
|
@ -240,7 +240,7 @@ bool Internat::SanitiseFilename(wxString &name, const wxString &sub)
|
||||
// Special Mac stuff
|
||||
// '/' is permitted in file names as seen in dialogs, even though it is
|
||||
// the path separator. The "real" filename as seen in the terminal has ':'.
|
||||
// Do NOT return true if this is the only subsitution.
|
||||
// Do NOT return true if this is the only substitution.
|
||||
name.Replace(wxT("/"), wxT(":"));
|
||||
#endif
|
||||
|
||||
@ -325,3 +325,17 @@ wxString TranslatableString::Translation() const
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
TranslatableString &TranslatableString::operator +=(
|
||||
const TranslatableString &arg )
|
||||
{
|
||||
auto prevFormatter = mFormatter;
|
||||
mFormatter = [prevFormatter, arg](const wxString &str){
|
||||
if (str.empty())
|
||||
return prevFormatter ? prevFormatter({}) : wxString{};
|
||||
else
|
||||
return (prevFormatter ? prevFormatter(str) : str)
|
||||
+ arg.Translation();
|
||||
};
|
||||
return *this;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user