From eeedbc79820287d3daa21d7223a0d468aaa7e41d Mon Sep 17 00:00:00 2001 From: Jaime Bernardo Date: Wed, 28 Feb 2024 14:32:42 +0000 Subject: [PATCH] [General]Default to English when a resource is not found (#31614) --- .github/actions/spell-check/expect.txt | 1 + src/common/utils/resources.h | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/.github/actions/spell-check/expect.txt b/.github/actions/spell-check/expect.txt index 7b4900ccb1..0b3d155b3b 100644 --- a/.github/actions/spell-check/expect.txt +++ b/.github/actions/spell-check/expect.txt @@ -839,6 +839,7 @@ lwin LZero majortype makecab +MAKELANGID MAKEINTRESOURCE MAKEINTRESOURCEA MAKEINTRESOURCEW diff --git a/src/common/utils/resources.h b/src/common/utils/resources.h index 7a7fd637ea..00caff6f70 100644 --- a/src/common/utils/resources.h +++ b/src/common/utils/resources.h @@ -2,6 +2,7 @@ #define WIN32_LEAN_AND_MEAN #include #include +#include // Get a string from the resource file inline std::wstring get_resource_string(UINT resource_id, HINSTANCE instance, const wchar_t* fallback) @@ -10,7 +11,22 @@ inline std::wstring get_resource_string(UINT resource_id, HINSTANCE instance, co auto length = LoadStringW(instance, resource_id, reinterpret_cast(&text_ptr), 0); if (length == 0) { - return fallback; + // Try to load en-us string as the first fallback. + WORD english_language = MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US); + ATL::CStringW english_string; + try + { + if (!english_string.LoadStringW(instance, resource_id, english_language)) + { + return fallback; + } + } + catch (...) + { + return fallback; + } + + return std::wstring(english_string); } else {