From 825461e2b0bb9bbf3ce14ff31ddd8102ab61c39b Mon Sep 17 00:00:00 2001 From: Simon Rozman Date: Wed, 5 Oct 2016 12:10:57 +0200 Subject: [PATCH] wxInitializeLocale moved to wxExtend --- include/wxex/common.h | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/include/wxex/common.h b/include/wxex/common.h index 599a048..a3c3317 100644 --- a/include/wxex/common.h +++ b/include/wxex/common.h @@ -39,6 +39,7 @@ #if !defined(RC_INVOKED) && !defined(MIDL_PASS) #include +#include #include #include @@ -121,5 +122,40 @@ inline bool wxModifyStyleEx(_In_ WXHWND hWnd, _In_ DWORD dwRemove, _In_ DWORD dw return true; } + +/// +/// Inizializes wxWidgets localization scheme +/// +/// The language identifier is read from "Language" configuration string (ll_CC form expected). +/// The path to folder containing localization catalogue PO files is read from "LocalizationRepositoryPath" configuration string. +/// +/// \param[inout] locale Locale to initialize +/// +/// \returns +/// - \c true when initialization succeeded +/// - \c false otherwise +/// +inline bool wxInitializeLocale(wxLocale &locale) +{ + // Read language from configuration. + wxLanguage lang_code; + wxString lang; + if (wxConfigBase::Get()->Read(wxT("Language"), &lang)) { + const wxLanguageInfo *lang_info = wxLocale::FindLanguageInfo(lang); + lang_code = lang_info ? (wxLanguage)lang_info->Language : wxLANGUAGE_DEFAULT; + } else + lang_code = wxLANGUAGE_DEFAULT; + + if (wxLocale::IsAvailable(lang_code)) { + // Language is "available". Well... Known actually. + wxString sPath; + if (wxConfigBase::Get()->Read(wxT("LocalizationRepositoryPath"), &sPath)) + locale.AddCatalogLookupPathPrefix(sPath); + return locale.Init(lang_code); + } + + return false; +} + #endif // !defined(RC_INVOKED) && !defined(MIDL_PASS) #endif // !defined(__wxEXTEND_common_h__)