MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / GetCurrentLocale

Function GetCurrentLocale

src/os/windows/win32.cpp:401–414  ·  view source on GitHub ↗

Determine the current user's locale. */

Source from the content-addressed store, hash-verified

399
400/** Determine the current user's locale. */
401std::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
417static WCHAR _cur_iso_locale[16] = L"";

Callers 1

GetLocalCodeFunction · 0.50

Calls 2

sizeFunction · 0.50
formatFunction · 0.50

Tested by

no test coverage detected