diff --git a/include/wx/uilocale.h b/include/wx/uilocale.h index 039c6c2411..6176803008 100644 --- a/include/wx/uilocale.h +++ b/include/wx/uilocale.h @@ -158,12 +158,18 @@ public: // its dtor is not virtual. ~wxUILocale(); + // Return the locale ID representing the default system locale, which would + // be set is UseDefault() is called. + static wxLocaleIdent GetSystemLocaleId(); + // Try to get user's (or OS's) preferred language setting. // Return wxLANGUAGE_UNKNOWN if the language-guessing algorithm failed + // Prefer using GetSystemLocaleId() above. static int GetSystemLanguage(); // Try to get user's (or OS's) default locale setting. // Return wxLANGUAGE_UNKNOWN if the locale-guessing algorithm failed + // Prefer using GetSystemLocaleId() above. static int GetSystemLocale(); // Try to retrieve a list of user's (or OS's) preferred UI languages. diff --git a/interface/wx/uilocale.h b/interface/wx/uilocale.h index d61e11d928..67dc2364e7 100644 --- a/interface/wx/uilocale.h +++ b/interface/wx/uilocale.h @@ -289,7 +289,7 @@ public: by the operating system (for example, Windows 7 and below), the user's default @em locale will be used. - @see wxTranslations::GetBestTranslation(). + @see wxTranslations::GetBestTranslation(), GetSystemLocaleId(). */ static int GetSystemLanguage(); @@ -297,7 +297,8 @@ public: Tries to detect the user's default locale setting. Returns the ::wxLanguage value or @c wxLANGUAGE_UNKNOWN if the locale-guessing - algorithm failed. + algorithm failed or if the locale can't be described using solely a + language constant. Consider using GetSystemLocaleId() in this case. @note This function works with @em locales and returns the user's default locale. This may be, and usually is, the same as their preferred UI @@ -308,7 +309,19 @@ public: @see wxTranslations::GetBestTranslation(). */ - static int GetSystemLocale();}; + static int GetSystemLocale(); + + /** + Return the description of the default system locale. + + This function can always represent the system locale, even when using + a language and region pair that doesn't correspond to any of the + predefined ::wxLanguage constants, such as e.g. "fr-DE", which means + French language used with German locale settings. + + @since 3.3.0 + */ +}; /** Return the format to use for formatting user-visible dates. diff --git a/src/common/uilocale.cpp b/src/common/uilocale.cpp index bf24482e7e..49de63fcdc 100644 --- a/src/common/uilocale.cpp +++ b/src/common/uilocale.cpp @@ -632,6 +632,13 @@ wxUILocale::~wxUILocale() } +/* static */ +wxLocaleIdent wxUILocale::GetSystemLocaleId() +{ + wxUILocale defaultLocale(wxUILocaleImpl::CreateUserDefault()); + return defaultLocale.GetLocaleId(); +} + /*static*/ int wxUILocale::GetSystemLanguage() { @@ -677,11 +684,9 @@ int wxUILocale::GetSystemLanguage() /*static*/ int wxUILocale::GetSystemLocale() { - // Create default wxUILocale - wxUILocale defaultLocale(wxUILocaleImpl::CreateUserDefault()); - const wxLocaleIdent locId = defaultLocale.GetLocaleId(); + const wxLocaleIdent locId = GetSystemLocaleId(); - // Find corresponding wxLanguageInfo + // Find wxLanguageInfo corresponding to the default locale. const wxLanguageInfo* defaultLanguage = wxUILocale::FindLanguageInfo(locId); // Check if it really corresponds to this locale: we could find it via the diff --git a/tests/intl/intltest.cpp b/tests/intl/intltest.cpp index d34c0d90f2..a82330d35d 100644 --- a/tests/intl/intltest.cpp +++ b/tests/intl/intltest.cpp @@ -480,9 +480,11 @@ wxString GetLocaleDesc(const char* when) // ways to change the current locale. TEST_CASE("wxUILocale::ShowSystem", "[.]") { - WARN("System locale:\t" + WARN("System locale identifier:\t" + << wxUILocale::GetSystemLocaleId().GetTag() << "\n" + "System locale as language:\t" << GetLangName(wxUILocale::GetSystemLocale()) << "\n" - "System language:\t" + "System language identifier:\t" << GetLangName(wxUILocale::GetSystemLanguage())); WARN(GetLocaleDesc("Before calling any locale functions"));