diff --git a/Source/Engine/Engine/Engine.cpp b/Source/Engine/Engine/Engine.cpp index b53b69741..78b7da1a1 100644 --- a/Source/Engine/Engine/Engine.cpp +++ b/Source/Engine/Engine/Engine.cpp @@ -622,7 +622,7 @@ void EngineImpl::InitLog() // Log product info LOG(Info, "Product: {0}, Company: {1}", Globals::ProductName, Globals::CompanyName); - LOG(Info, "Current culture: {0}", Platform::GetUserLocaleName()); + LOG(Info, "Current language: {}, culture: {}", Platform::GetUserLanguage(), Platform::GetUserLocaleName()); LOG(Info, "Command line: {0}", CommandLine); LOG(Info, "Base folder: {0}", Globals::StartupFolder); LOG(Info, "Binaries folder: {0}", Globals::BinariesFolder); diff --git a/Source/Engine/Localization/Localization.cpp b/Source/Engine/Localization/Localization.cpp index acc265025..fccdae9fa 100644 --- a/Source/Engine/Localization/Localization.cpp +++ b/Source/Engine/Localization/Localization.cpp @@ -328,7 +328,8 @@ bool LocalizationService::Init() PROFILE_MEM(Localization); // Use system language as default - CurrentLanguage = CurrentCulture = CultureInfo(Platform::GetUserLocaleName()); + CurrentLanguage = CultureInfo(Platform::GetUserLanguage()); + CurrentCulture = CultureInfo(Platform::GetUserLocaleName()); // Setup localization Instance.OnLocalizationChanged(); diff --git a/Source/Engine/Platform/Base/PlatformBase.cpp b/Source/Engine/Platform/Base/PlatformBase.cpp index 4512a59b3..2c6415470 100644 --- a/Source/Engine/Platform/Base/PlatformBase.cpp +++ b/Source/Engine/Platform/Base/PlatformBase.cpp @@ -595,6 +595,11 @@ ScreenOrientationType PlatformBase::GetScreenOrientationType() return ScreenOrientationType::Unknown; } +String PlatformBase::GetUserLanguage() +{ + return Platform::GetUserLocaleName(); +} + String PlatformBase::GetUserName() { return Users.Count() != 0 ? Users[0]->GetName() : String::Empty; diff --git a/Source/Engine/Platform/Base/PlatformBase.h b/Source/Engine/Platform/Base/PlatformBase.h index 44a0c8415..cc1c1f7a8 100644 --- a/Source/Engine/Platform/Base/PlatformBase.h +++ b/Source/Engine/Platform/Base/PlatformBase.h @@ -613,7 +613,12 @@ public: API_PROPERTY() static ScreenOrientationType GetScreenOrientationType(); /// - /// Gets the current locale culture (eg. "pl-PL" or "en-US"). + /// Gets the current user display language used to localize texts. Returns name of the culture (eg. "pl-PL" or "en-US"), use CultureInfo for display name of the language. + /// + API_PROPERTY() static String GetUserLanguage(); + + /// + /// Gets the current user locale culture used to localize numbers, currency and dates. Returns name of the culture (eg. "pl-PL" or "en-US"), use CultureInfo for display name of the language. /// API_PROPERTY() static String GetUserLocaleName() = delete; diff --git a/Source/Engine/Platform/Windows/WindowsPlatform.cpp b/Source/Engine/Platform/Windows/WindowsPlatform.cpp index 42accf298..5bf359829 100644 --- a/Source/Engine/Platform/Windows/WindowsPlatform.cpp +++ b/Source/Engine/Platform/Windows/WindowsPlatform.cpp @@ -61,7 +61,7 @@ void FlaxDbgHelpUnlock() namespace { - String UserLocale, ComputerName, WindowsName; + String UserLanguage, UserLocale, ComputerName, WindowsName; HANDLE EngineMutex = nullptr; Rectangle VirtualScreenBounds(0.0f, 0.0f, 0.0f, 0.0f); int32 VersionMajor = 0; @@ -766,12 +766,18 @@ bool WindowsPlatform::Init() DWORD tmp; Char buffer[256]; + ULONG bufferSize = ARRAY_COUNT(buffer), languagesCount = 0; - // Get user locale string - if (GetUserDefaultLocaleName(buffer, LOCALE_NAME_MAX_LENGTH)) + // Get user locale strings + if (GetUserDefaultLocaleName(buffer, (int)bufferSize)) { UserLocale = String(buffer); } + if (GetUserPreferredUILanguages(MUI_LANGUAGE_NAME, &languagesCount, buffer, &bufferSize)) + { + // Get the first language + UserLanguage = String(buffer); + } // Get computer name string if (GetComputerNameW(buffer, &tmp)) @@ -935,6 +941,11 @@ int32 WindowsPlatform::GetDpi() return SystemDpi; } +String WindowsPlatform::GetUserLanguage() +{ + return UserLanguage.HasChars() ? UserLanguage : UserLocale; +} + String WindowsPlatform::GetUserLocaleName() { return UserLocale; diff --git a/Source/Engine/Platform/Windows/WindowsPlatform.h b/Source/Engine/Platform/Windows/WindowsPlatform.h index a8f0e4996..0179058ba 100644 --- a/Source/Engine/Platform/Windows/WindowsPlatform.h +++ b/Source/Engine/Platform/Windows/WindowsPlatform.h @@ -71,6 +71,7 @@ public: static Version GetSystemVersion(); static BatteryInfo GetBatteryInfo(); static int32 GetDpi(); + static String GetUserLanguage(); static String GetUserLocaleName(); static String GetComputerName(); static bool GetHasFocus();