From f55571ee5dffad775cd4043a273f232d7e8330ee Mon Sep 17 00:00:00 2001 From: Pokechu22 Date: Wed, 10 Nov 2021 20:14:57 -0800 Subject: [PATCH] Common/MsgHandler: Fix PanicAlertFmtT not actually being translated --- Source/Core/Common/MsgHandler.h | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/Source/Core/Common/MsgHandler.h b/Source/Core/Common/MsgHandler.h index e99b587b7b..dc232fc785 100644 --- a/Source/Core/Common/MsgHandler.h +++ b/Source/Core/Common/MsgHandler.h @@ -41,21 +41,28 @@ bool MsgAlertFmt(bool yes_no, MsgType style, Common::Log::LogType log_type, cons static_assert(NumFields == sizeof...(args), "Unexpected number of replacement fields in format string; did you pass too few or " "too many arguments?"); + static_assert(fmt::is_compile_string::value); return MsgAlertFmtImpl(yes_no, style, log_type, format, fmt::make_args_checked(format, args...)); } template 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, "Translatable strings must use positional arguments (e.g. {0} instead of {})"); static_assert(NumFields == sizeof...(args), "Unexpected number of replacement fields in format string; did you pass too few or " "too many arguments?"); - return MsgAlertFmtImpl(yes_no, style, log_type, format, - fmt::make_args_checked(format, args...)); + static_assert(fmt::is_compile_string::value); + // 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(format, args...); + return MsgAlertFmtImpl(yes_no, style, log_type, translated_format, arg_list); } void SetEnableAlert(bool enable); @@ -78,7 +85,8 @@ std::string FmtFormatT(const char* string, Args&&... args) #define GenericAlertFmtT(yes_no, style, log_type, format, ...) \ Common::MsgAlertFmtT( \ - 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, ...) \ GenericAlertFmt(false, Common::MsgType::Information, MASTER_LOG, format, ##__VA_ARGS__)