From b654dbfa5f3e4a4d02f72023f7c5895635aa6396 Mon Sep 17 00:00:00 2001 From: Daniel Wilhelm Date: Fri, 18 Apr 2014 17:12:17 +0200 Subject: 3.18 --- shared/localization.cpp | 58 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 38 insertions(+), 20 deletions(-) (limited to 'shared/localization.cpp') diff --git a/shared/localization.cpp b/shared/localization.cpp index 825773d9..36773fc3 100644 --- a/shared/localization.cpp +++ b/shared/localization.cpp @@ -100,26 +100,6 @@ std::string getFileStream(const wxString& filename) //return empty string on err FFSLocale::FFSLocale(const wxString& filename, wxLanguage languageId) : langId_(languageId) //throw (lngfile::ParsingError, PluralForm::ParsingError) { - static class StaticInit - { - public: - StaticInit() : loc(wxLANGUAGE_DEFAULT) //wxLocale: we need deferred initialization, sigh... - { - //::setlocale (LC_ALL, ""); -> implicitly called by wxLocale - const lconv* localInfo = ::localeconv(); - - //actually these two parameters are language dependent, but we take system setting to handle all kinds of language derivations - THOUSANDS_SEPARATOR = wxString::FromUTF8(localInfo->thousands_sep); - - // why not working? - // THOUSANDS_SEPARATOR = std::use_facet >(std::locale("")).thousands_sep(); - // DECIMAL_POINT = std::use_facet >(std::locale("")).decimal_point(); - } - private: - wxLocale loc; //required for RTL language support (and nothing else) - } dummy; - - const std::string inputStream = getFileStream(filename); if (inputStream.empty()) throw lngfile::ParsingError(0, 0); @@ -322,6 +302,7 @@ wxLanguage mapLanguageDialect(wxLanguage language) return wxLANGUAGE_SWEDISH; //case wxLANGUAGE_CZECH: + //case wxLANGUAGE_DANISH: //case wxLANGUAGE_FINNISH: //case wxLANGUAGE_GREEK: //case wxLANGUAGE_JAPANESE: @@ -374,6 +355,37 @@ wxLanguage mapLanguageDialect(wxLanguage language) } +class CustomLocale +{ +public: + CustomLocale(int selectedLng) + { + const wxLanguageInfo* sysLngInfo = wxLocale::GetLanguageInfo(wxLocale::GetSystemLanguage()); + const wxLanguageInfo* selLngInfo = wxLocale::GetLanguageInfo(selectedLng); + + bool sysLangIsRTL = sysLngInfo ? sysLngInfo->LayoutDirection == wxLayout_RightToLeft : false; + bool selectedLangIsRTL = selLngInfo ? selLngInfo->LayoutDirection == wxLayout_RightToLeft : false; + + if (sysLangIsRTL == selectedLangIsRTL) + loc.Init(wxLANGUAGE_DEFAULT); //use sys-lang to preserve sub-language specific rules (e.g. german swiss number punctation) + else + loc.Init(selectedLng); + + //::setlocale (LC_ALL, ""); -> implicitly called by wxLocale + const lconv* localInfo = ::localeconv(); + + //actually these two parameters are language dependent, but we take system setting to handle all kinds of language derivations + THOUSANDS_SEPARATOR = wxString::FromUTF8(localInfo->thousands_sep); + + // why not working? + // THOUSANDS_SEPARATOR = std::use_facet >(std::locale("")).thousands_sep(); + // DECIMAL_POINT = std::use_facet >(std::locale("")).decimal_point(); + } +private: + wxLocale loc; //required for RTL language support (and nothing else) +}; + + void zen::setLanguage(int language) { //(try to) retrieve language file @@ -386,6 +398,12 @@ void zen::setLanguage(int language) } + //handle RTL swapping: we need wxWidgets to do this + static std::auto_ptr dummy; + dummy.reset(); //avoid global locale lifetime overlap! wxWidgets cannot handle this and will crash! + dummy.reset(new CustomLocale(languageFile.empty() ? wxLANGUAGE_ENGLISH : language)); + + //reset to english language; in case of error show error message just once zen::setTranslator(); -- cgit