Skip to content

Commit

Permalink
[General]Default to English when a resource is not found (#31614)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaimecbernardo committed Feb 28, 2024
1 parent e5795ef commit eeedbc7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions .github/actions/spell-check/expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,7 @@ lwin
LZero
majortype
makecab
MAKELANGID
MAKEINTRESOURCE
MAKEINTRESOURCEA
MAKEINTRESOURCEW
Expand Down
18 changes: 17 additions & 1 deletion src/common/utils/resources.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <string>
#include <atlstr.h>

// Get a string from the resource file
inline std::wstring get_resource_string(UINT resource_id, HINSTANCE instance, const wchar_t* fallback)
Expand All @@ -10,7 +11,22 @@ inline std::wstring get_resource_string(UINT resource_id, HINSTANCE instance, co
auto length = LoadStringW(instance, resource_id, reinterpret_cast<wchar_t*>(&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
{
Expand Down

0 comments on commit eeedbc7

Please sign in to comment.