diff options
| author | Pokechu22 <Pokechu022@gmail.com> | 2021-11-10 20:14:57 -0800 |
|---|---|---|
| committer | Pokechu22 <Pokechu022@gmail.com> | 2022-01-09 12:44:14 -0800 |
| commit | f55571ee5dffad775cd4043a273f232d7e8330ee (patch) | |
| tree | 3d00a3a0ef11b6be26c9061db073efcb520c2a21 /Source | |
| parent | 2a5016c2f8be6a12b30eb8001defdc6c24415f27 (diff) | |
Common/MsgHandler: Fix PanicAlertFmtT not actually being translated
Diffstat (limited to 'Source')
| -rw-r--r-- | Source/Core/Common/MsgHandler.h | 16 |
1 files 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<S>::value); return MsgAlertFmtImpl(yes_no, style, log_type, format, fmt::make_args_checked<Args...>(format, 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, - 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<Args...>(format, args...)); + static_assert(fmt::is_compile_string<S>::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<Args...>(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<Common::CountFmtReplacementFields(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, ...) \ GenericAlertFmt(false, Common::MsgType::Information, MASTER_LOG, format, ##__VA_ARGS__) |
