Determine the current user's locale. */
| 399 | |
| 400 | /** Determine the current user's locale. */ |
| 401 | std::optional<std::string> GetCurrentLocale(const char *) |
| 402 | { |
| 403 | const LANGID userUiLang = GetUserDefaultUILanguage(); |
| 404 | const LCID userUiLocale = MAKELCID(userUiLang, SORT_DEFAULT); |
| 405 | |
| 406 | char lang[9], country[9]; |
| 407 | if (GetLocaleInfoA(userUiLocale, LOCALE_SISO639LANGNAME, lang, static_cast<int>(std::size(lang))) == 0 || |
| 408 | GetLocaleInfoA(userUiLocale, LOCALE_SISO3166CTRYNAME, country, static_cast<int>(std::size(country))) == 0) { |
| 409 | /* Unable to retrieve the locale. */ |
| 410 | return std::nullopt; |
| 411 | } |
| 412 | /* Format it as 'en_us'. */ |
| 413 | return fmt::format("{}_{}", std::string_view{lang, 2}, std::string_view{country, 2}); |
| 414 | } |
| 415 | |
| 416 | |
| 417 | static WCHAR _cur_iso_locale[16] = L""; |
no test coverage detected