11#ifndef __AUDACITY_TRANSLATABLE_STRING__
12#define __AUDACITY_TRANSLATABLE_STRING__
52 : mFormatter{
std::move(formatter) }
61 : mFormatter(
std::move(
str.mFormatter ) )
63 mMsgid.swap(
str.mMsgid );
67 mFormatter = std::move(
str.mFormatter );
68 mMsgid.swap(
str.mMsgid );
72 bool empty()
const {
return mMsgid.empty(); }
82 wxString
Debug()
const {
return DoFormat(
true ); }
95 bool IsVerbatim()
const;
102 template<
typename... Args >
105 auto prevFormatter = mFormatter;
106 this->mFormatter = [prevFormatter, args...]
107 (
const wxString &
str,
Request request) -> wxString {
109 case Request::Context:
111 case Request::Format:
112 case Request::DebugFormat:
114 bool debug = request == Request::DebugFormat;
115 return wxString::Format(
127 template<
typename... Args >
130 return std::move(
Format( std::forward<Args>(args)... ) );
139 this->mFormatter = [context]
140 (
const wxString &
str,
Request request) -> wxString {
142 case Request::Context:
144 case Request::DebugFormat:
145 return DoSubstitute( {},
str, context, true );
146 case Request::Format:
148 return DoSubstitute( {},
str, context, false );
155 return std::move( Context( context ) );
166 {
return std::move(
Join( std::move(arg), separator ) ); }
170 Join( std::move( arg ) );
195 {
return std::move( Strip( options ) ); }
208 : mFormatter{ NullContextFormatter }
224 static wxString DoGetContext(
const Formatter &formatter );
225 static wxString DoSubstitute(
227 const wxString &
format,
const wxString &context,
bool debug );
229 {
return DoSubstitute(
230 mFormatter, mMsgid, DoGetContext(mFormatter), debug ); }
232 static wxString DoChooseFormat(
233 const Formatter &formatter,
234 const wxString &singular,
const wxString &plural,
unsigned nn,
bool debug );
241 const std::reference_wrapper<T> &arg,
bool debug )
251 template<
typename... Args >
256 std::template get< N >( std::forward_as_tuple( args... ) );
258 auto nn =
static_cast<unsigned>(
259 std::max<unsigned long long>( 0, selector )
261 auto plural = this->pluralStr;
263 this->ts.
mFormatter = [prevFormatter, plural, nn, args...]
264 (
const wxString &
str,
Request request) -> wxString {
266 case Request::Context:
268 case Request::Format:
269 case Request::DebugFormat:
272 bool debug = request == Request::DebugFormat;
273 return wxString::Format(
275 prevFormatter,
str, plural, nn, debug ),
281 return std::move(ts);
292 return std::move(x += std::move(y));
304 const wxString &stdstr =
str.mMsgid.ToStdWstring();
305 using Hasher = hash< wxString >;
306 return Hasher{}( stdstr );
312template<
typename Sink >
315 return sink <<
str.Translation();
ResultType Join(const ContainerType< ResultType, Rest... > &container, const SeparatorType &separator)
TranslatableString operator+(TranslatableString x, TranslatableString y)
Sink & operator<<(Sink &sink, const TranslatableString &str)
Allow TranslatableString to work with shift output operators.
bool TranslationLess(const TranslatableString &a, const TranslatableString &b)
A commonly needed sort comparator, which depends on the language setting.
TranslatableString Verbatim(wxString str)
Require calls to the one-argument constructor to go through this distinct global function name.
std::vector< TranslatableString > TranslatableStrings
bool operator==(const WaveTrackLocation &a, const WaveTrackLocation &b)
bool operator!=(const WaveTrackLocation &a, const WaveTrackLocation &b)
An explicitly nonlocalized string, not meant for the user to see.
Class to construct the HTTP request.
Holds a msgid for the translation catalog; may also bind format arguments.
TranslatableString & operator=(const TranslatableString &)=default
static wxString DoChooseFormat(const Formatter &formatter, const wxString &singular, const wxString &plural, unsigned nn, bool debug)
static const wxChar *const NullContextName
std::function< wxString(const wxString &, Request) > Formatter
A multi-purpose function, depending on the enum argument.
wxString DoFormat(bool debug) const
TranslatableString(TranslatableString &&str)
TranslatableString & Context(const wxString &context) &
Choose a non-default and non-null disambiguating context for lookups.
TranslatableString & operator=(TranslatableString &&str)
static const TranslatableString Inaudible
A special string value that will have no screen reader pronunciation.
TranslatableString && Context(const wxString &context) &&
static wxString DoGetContext(const Formatter &formatter)
TranslatableString && Join(TranslatableString arg, const wxString &separator={}) &&
TranslatableString && Strip(unsigned options=MenuCodes) &&
TranslatableString && Format(Args &&...args) &&
static const T & TranslateArgument(const T &arg, bool)
TranslatableString(wxString str)
Construct a TranslatableString that does no translation but passes str verbatim.
TranslatableString & Strip(unsigned options=MenuCodes) &
wxString StrippedTranslation() const
static auto TranslateArgument(const std::reference_wrapper< T > &arg, bool debug) -> decltype(TranslatableString::TranslateArgument(arg.get(), debug))
This allows you to wrap arguments of Format in std::cref.
static wxString DoSubstitute(const Formatter &formatter, const wxString &format, const wxString &context, bool debug)
wxString Translation() const
TranslatableString(const TranslatableString &)=default
PluralTemp< N > Plural(const wxString &pluralStr) &&
Implements the XP macro.
static wxString TranslateArgument(const TranslatableString &arg, bool debug)
TranslatableString & Format(Args &&...args) &
Capture variadic format arguments (by copy) when there is no plural.
wxString Debug() const
Format as an English string for debugging logs and developers' eyes, not for end users.
TranslatableString(wxString str, Formatter formatter)
TranslatableString Stripped(unsigned options=MenuCodes) const
non-mutating, constructs another TranslatableString object
static const Formatter NullContextFormatter
const wxString & pluralStr
TranslatableString && operator()(Args &&... args)