diff options
author | Daniel Wilhelm <daniel@wili.li> | 2014-04-18 17:12:17 +0200 |
---|---|---|
committer | Daniel Wilhelm <daniel@wili.li> | 2014-04-18 17:12:17 +0200 |
commit | b654dbfa5f3e4a4d02f72023f7c5895635aa6396 (patch) | |
tree | 8c1dfe7f638c0fc7afc1d08bc2fc0fd0f8646e5e /shared/localization.cpp | |
parent | 3.17 (diff) | |
download | FreeFileSync-b654dbfa5f3e4a4d02f72023f7c5895635aa6396.tar.gz FreeFileSync-b654dbfa5f3e4a4d02f72023f7c5895635aa6396.tar.bz2 FreeFileSync-b654dbfa5f3e4a4d02f72023f7c5895635aa6396.zip |
3.18
Diffstat (limited to 'shared/localization.cpp')
-rw-r--r-- | shared/localization.cpp | 58 |
1 files changed, 38 insertions, 20 deletions
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::numpunct<wchar_t> >(std::locale("")).thousands_sep(); - // DECIMAL_POINT = std::use_facet<std::numpunct<wchar_t> >(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::numpunct<wchar_t> >(std::locale("")).thousands_sep(); + // DECIMAL_POINT = std::use_facet<std::numpunct<wchar_t> >(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<CustomLocale> 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(); |