Common/MsgHandler: Fix PanicAlertFmtT not actually being translated
This commit is contained in:
parent
2a5016c2f8
commit
f55571ee5d
|
@ -41,21 +41,28 @@ bool MsgAlertFmt(bool yes_no, MsgType style, Common::Log::LogType log_type, cons
|
||||||
static_assert(NumFields == sizeof...(args),
|
static_assert(NumFields == sizeof...(args),
|
||||||
"Unexpected number of replacement fields in format string; did you pass too few or "
|
"Unexpected number of replacement fields in format string; did you pass too few or "
|
||||||
"too many arguments?");
|
"too many arguments?");
|
||||||
|
static_assert(fmt::is_compile_string<S>::value);
|
||||||
return MsgAlertFmtImpl(yes_no, style, log_type, format,
|
return MsgAlertFmtImpl(yes_no, style, log_type, format,
|
||||||
fmt::make_args_checked<Args...>(format, args...));
|
fmt::make_args_checked<Args...>(format, args...));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <std::size_t NumFields, bool has_non_positional_args, typename S, typename... Args>
|
template <std::size_t NumFields, bool has_non_positional_args, typename S, typename... Args>
|
||||||
bool MsgAlertFmtT(bool yes_no, MsgType style, Common::Log::LogType log_type, const S& format,
|
bool MsgAlertFmtT(bool yes_no, MsgType style, Common::Log::LogType log_type, const S& format,
|
||||||
const Args&... args)
|
fmt::string_view translated_format, const Args&... args)
|
||||||
{
|
{
|
||||||
static_assert(!has_non_positional_args,
|
static_assert(!has_non_positional_args,
|
||||||
"Translatable strings must use positional arguments (e.g. {0} instead of {})");
|
"Translatable strings must use positional arguments (e.g. {0} instead of {})");
|
||||||
static_assert(NumFields == sizeof...(args),
|
static_assert(NumFields == sizeof...(args),
|
||||||
"Unexpected number of replacement fields in format string; did you pass too few or "
|
"Unexpected number of replacement fields in format string; did you pass too few or "
|
||||||
"too many arguments?");
|
"too many arguments?");
|
||||||
return MsgAlertFmtImpl(yes_no, style, log_type, format,
|
static_assert(fmt::is_compile_string<S>::value);
|
||||||
fmt::make_args_checked<Args...>(format, args...));
|
// It's only possible for us to compile-time check the English-language string.
|
||||||
|
// make_args_checked uses static_asserts to verify that a string is formattable with the given
|
||||||
|
// arguments. But it can't do that if the string varies at runtime, so we can't check
|
||||||
|
// translations. Still, verifying that the English string is correct will help ensure that
|
||||||
|
// translations use valid strings.
|
||||||
|
auto arg_list = fmt::make_args_checked<Args...>(format, args...);
|
||||||
|
return MsgAlertFmtImpl(yes_no, style, log_type, translated_format, arg_list);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetEnableAlert(bool enable);
|
void SetEnableAlert(bool enable);
|
||||||
|
@ -78,7 +85,8 @@ std::string FmtFormatT(const char* string, Args&&... args)
|
||||||
#define GenericAlertFmtT(yes_no, style, log_type, format, ...) \
|
#define GenericAlertFmtT(yes_no, style, log_type, format, ...) \
|
||||||
Common::MsgAlertFmtT<Common::CountFmtReplacementFields(format), \
|
Common::MsgAlertFmtT<Common::CountFmtReplacementFields(format), \
|
||||||
Common::ContainsNonPositionalArguments(format)>( \
|
Common::ContainsNonPositionalArguments(format)>( \
|
||||||
yes_no, style, Common::Log::LogType::log_type, FMT_STRING(format), ##__VA_ARGS__)
|
yes_no, style, Common::Log::LogType::log_type, FMT_STRING(format), \
|
||||||
|
Common::GetStringT(format), ##__VA_ARGS__)
|
||||||
|
|
||||||
#define SuccessAlertFmt(format, ...) \
|
#define SuccessAlertFmt(format, ...) \
|
||||||
GenericAlertFmt(false, Common::MsgType::Information, MASTER_LOG, format, ##__VA_ARGS__)
|
GenericAlertFmt(false, Common::MsgType::Information, MASTER_LOG, format, ##__VA_ARGS__)
|
||||||
|
|
Loading…
Reference in New Issue