From 7836dfbc776cee01fd372691ba6a184098fbea10 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 14 Jul 2017 18:20:16 +0200 Subject: [PATCH] Make wxLanguageInfo::GetLocaleName() consistent across platforms Check that the locale can be indeed set to the given string in Unix version too, there doesn't seem to be any good reason to do it for MSW only. --- include/wx/intl.h | 10 ++-------- interface/wx/intl.h | 9 +++++++-- src/common/intl.cpp | 9 ++++++++- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/include/wx/intl.h b/include/wx/intl.h index c2020ddbfc..26c940fb1f 100644 --- a/include/wx/intl.h +++ b/include/wx/intl.h @@ -72,17 +72,11 @@ struct WXDLLIMPEXP_BASE wxLanguageInfo #endif // __WINDOWS__ // return the locale name corresponding to this language usable with - // setlocale() on the current system + // setlocale() on the current system or empty string if this locale is not + // supported wxString GetLocaleName() const; }; -// for Unix systems GetLocaleName() is trivial so implement it inline here, for -// MSW it's implemented in intl.cpp -#ifndef __WINDOWS__ -inline wxString wxLanguageInfo::GetLocaleName() const { return CanonicalName; } -#endif // !__WINDOWS__ - - // ---------------------------------------------------------------------------- // wxLocaleCategory: the category of locale settings // ---------------------------------------------------------------------------- diff --git a/interface/wx/intl.h b/interface/wx/intl.h index 70f21122b2..aa77038d23 100644 --- a/interface/wx/intl.h +++ b/interface/wx/intl.h @@ -55,8 +55,13 @@ struct wxLanguageInfo /// @onlyfor{wxmsw} wxUint32 GetLCID() const; - /// Return the locale name corresponding to this language usable with - /// @c setlocale() on the current system. + /** + Return the locale name corresponding to this language usable with + @c setlocale() on the current system. + + If setting locale for this language is not supported, the returned + string is empty. + */ wxString GetLocaleName() const; }; diff --git a/src/common/intl.cpp b/src/common/intl.cpp index e10a29c269..4c128e0014 100644 --- a/src/common/intl.cpp +++ b/src/common/intl.cpp @@ -205,7 +205,14 @@ wxString wxLanguageInfo::GetLocaleName() const return CanSetLocale(locale) ? locale : wxString(); } -#endif // __WINDOWS__ +#else // !__WINDOWS__ + +wxString wxLanguageInfo::GetLocaleName() const +{ + return CanSetLocale(CanonicalName) ? CanonicalName : wxString(); +} + +#endif // __WINDOWS__/!__WINDOWS__ // ---------------------------------------------------------------------------- // wxLocale