mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 19:57:57 +01:00
[General]Default to English when a resource is not found (#31614)
This commit is contained in:
1
.github/actions/spell-check/expect.txt
vendored
1
.github/actions/spell-check/expect.txt
vendored
@@ -839,6 +839,7 @@ lwin
|
|||||||
LZero
|
LZero
|
||||||
majortype
|
majortype
|
||||||
makecab
|
makecab
|
||||||
|
MAKELANGID
|
||||||
MAKEINTRESOURCE
|
MAKEINTRESOURCE
|
||||||
MAKEINTRESOURCEA
|
MAKEINTRESOURCEA
|
||||||
MAKEINTRESOURCEW
|
MAKEINTRESOURCEW
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
#define WIN32_LEAN_AND_MEAN
|
#define WIN32_LEAN_AND_MEAN
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <atlstr.h>
|
||||||
|
|
||||||
// Get a string from the resource file
|
// Get a string from the resource file
|
||||||
inline std::wstring get_resource_string(UINT resource_id, HINSTANCE instance, const wchar_t* fallback)
|
inline std::wstring get_resource_string(UINT resource_id, HINSTANCE instance, const wchar_t* fallback)
|
||||||
@@ -9,9 +10,24 @@ inline std::wstring get_resource_string(UINT resource_id, HINSTANCE instance, co
|
|||||||
wchar_t* text_ptr;
|
wchar_t* text_ptr;
|
||||||
auto length = LoadStringW(instance, resource_id, reinterpret_cast<wchar_t*>(&text_ptr), 0);
|
auto length = LoadStringW(instance, resource_id, reinterpret_cast<wchar_t*>(&text_ptr), 0);
|
||||||
if (length == 0)
|
if (length == 0)
|
||||||
|
{
|
||||||
|
// 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;
|
return fallback;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
return fallback;
|
||||||
|
}
|
||||||
|
|
||||||
|
return std::wstring(english_string);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return { text_ptr, static_cast<std::size_t>(length) };
|
return { text_ptr, static_cast<std::size_t>(length) };
|
||||||
|
|||||||
Reference in New Issue
Block a user