diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2020-02-24 08:07:12 +0100 |
---|---|---|
committer | Michael Meeks <michael.meeks@collabora.com> | 2020-05-27 22:13:35 +0100 |
commit | b5a522a0d52db3974caf7ff2fe07c0dc41373fc9 (patch) | |
tree | bd54ac22f041024048fd658cffaef418931e617d | |
parent | 83bee181d933b2c1ce0f186808365c78dbe25e65 (diff) |
Fix currency symbol selection in Calc on mobile
In LOK we use one language identifier for both - UI language and
the locale used. This is a problem when we determine that we a
language for UI is not available and fall-back to the default
"en-US" langauge, which also changes the locale. This introduces
a separate variable that stores the language tag for the locale
independently to the language.
Another problem is that in some cases we don't reset the staticly
initialized data, when the new document is loaded, which is on
the other hand used to define which currency symbol is used as
SYSTEM locale. That can in some cases select the wrong currency
symbol even when we changed the locale to something else. This fix
introduces a reset function, which is triggered on every document
load.
Change-Id: I55c7f467600a832895f94346f8bf11a6ef6a1e49
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/89320
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Andras Timar <andras.timar@collabora.com>
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/89343
Tested-by: Jenkins
-rw-r--r-- | comphelper/source/misc/lok.cxx | 73 | ||||
-rw-r--r-- | desktop/CppunitTest_desktop_lib.mk | 1 | ||||
-rw-r--r-- | desktop/qa/desktop_lib/test_desktop_lib.cxx | 2 | ||||
-rw-r--r-- | desktop/source/lib/init.cxx | 39 | ||||
-rw-r--r-- | include/comphelper/lok.hxx | 7 | ||||
-rw-r--r-- | include/sfx2/lokhelper.hxx | 6 | ||||
-rw-r--r-- | include/sfx2/viewsh.hxx | 6 | ||||
-rw-r--r-- | include/svl/zforlist.hxx | 2 | ||||
-rw-r--r-- | sfx2/source/view/lokhelper.cxx | 32 | ||||
-rw-r--r-- | sfx2/source/view/viewsh.cxx | 11 | ||||
-rw-r--r-- | svl/source/numbers/zforlist.cxx | 10 | ||||
-rw-r--r-- | unotools/source/misc/syslocale.cxx | 2 |
12 files changed, 159 insertions, 32 deletions
diff --git a/comphelper/source/misc/lok.cxx b/comphelper/source/misc/lok.cxx index 097622b3c4eb..95c628dbbf61 100644 --- a/comphelper/source/misc/lok.cxx +++ b/comphelper/source/misc/lok.cxx @@ -38,7 +38,55 @@ static bool g_bLocalRendering(false); static Compat g_eCompatFlags(Compat::none); -static LanguageTag g_aLanguageTag("en-US", true); +namespace +{ + +class LanguageAndLocale +{ +private: + LanguageTag maLanguageTag; + LanguageTag maLocaleLanguageTag; + +public: + + LanguageAndLocale() + : maLanguageTag(LANGUAGE_NONE) + , maLocaleLanguageTag(LANGUAGE_NONE) + {} + + const LanguageTag& getLanguage() + { + return maLanguageTag; + } + + void setLanguage(const LanguageTag& rLanguageTag) + { + if (maLanguageTag != rLanguageTag) + { + SAL_INFO("comphelper.lok", "Setting language from " << maLanguageTag.getBcp47() << " to " << rLanguageTag.getBcp47()); + maLanguageTag = rLanguageTag; + } + } + + const LanguageTag& getLocale() + { + return maLocaleLanguageTag; + } + + void setLocale(const LanguageTag& rLocaleLanguageTag) + { + if (maLocaleLanguageTag != rLocaleLanguageTag) + { + SAL_INFO("comphelper.lok", "Setting locale from " << maLanguageTag.getBcp47() << " to " << rLocaleLanguageTag.getBcp47()); + maLocaleLanguageTag = rLocaleLanguageTag; + } + } + +}; + +} + +static LanguageAndLocale g_aLanguageAndLocale; /// Scaling of the cairo canvas painting for hi-dpi static double g_fDPIScale(1.0); @@ -173,23 +221,28 @@ void setCompatFlag(Compat flag) { g_eCompatFlags = static_cast<Compat>(g_eCompat bool isCompatFlagSet(Compat flag) { return (g_eCompatFlags & flag) == flag; } -void setLanguageTag(const OUString& lang, bool bCanonicalize) +void setLocale(const LanguageTag& rLanguageTag) { - g_aLanguageTag = LanguageTag(lang, bCanonicalize); + g_aLanguageAndLocale.setLocale(rLanguageTag); } -void setLanguageTag(const LanguageTag& languageTag) +const LanguageTag& getLocale() { - if (g_aLanguageTag != languageTag) - { - SAL_INFO("comphelper.lok", "setLanguageTag: from " << g_aLanguageTag.getBcp47() << " to " << languageTag.getBcp47()); - g_aLanguageTag = languageTag; - } + const LanguageTag& rLocale = g_aLanguageAndLocale.getLocale(); + SAL_WARN_IF(rLocale.getLanguageType() == LANGUAGE_NONE, "comphelper.lok", "Locale not set"); + return rLocale; +} + +void setLanguageTag(const LanguageTag& rLanguageTag) +{ + g_aLanguageAndLocale.setLanguage(rLanguageTag); } const LanguageTag& getLanguageTag() { - return g_aLanguageTag; + const LanguageTag& rLanguage = g_aLanguageAndLocale.getLanguage(); + SAL_WARN_IF(rLanguage.getLanguageType() == LANGUAGE_NONE, "comphelper.lok", "Language not set"); + return rLanguage; } bool isWhitelistedLanguage(const OUString& lang) diff --git a/desktop/CppunitTest_desktop_lib.mk b/desktop/CppunitTest_desktop_lib.mk index 5caca176e532..8b375235b05d 100644 --- a/desktop/CppunitTest_desktop_lib.mk +++ b/desktop/CppunitTest_desktop_lib.mk @@ -19,6 +19,7 @@ $(eval $(call gb_CppunitTest_use_libraries,desktop_lib, \ comphelper \ cppu \ cppuhelper \ + i18nlangtag \ sal \ sc \ scfilt \ diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx index a3f3ddac0cc4..0123037ec75d 100644 --- a/desktop/qa/desktop_lib/test_desktop_lib.cxx +++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx @@ -2816,7 +2816,7 @@ void DesktopLOKTest::testSpellcheckerMultiView() SvtSysLocaleOptions aSysLocaleOptions; aSysLocaleOptions.SetLocaleConfigString(aLangISO); aSysLocaleOptions.SetUILocaleConfigString(aLangISO); - comphelper::LibreOfficeKit::setLanguageTag(aLangISO, true); + comphelper::LibreOfficeKit::setLanguageTag(LanguageTag(aLangISO, true)); auto aSavedSettings = Application::GetSettings(); std::unique_ptr<Resetter> pResetter( diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx index 22d44fa7c3a8..57227e377cc8 100644 --- a/desktop/source/lib/init.cxx +++ b/desktop/source/lib/init.cxx @@ -47,6 +47,7 @@ #include <rtl/bootstrap.hxx> #include <rtl/strbuf.hxx> #include <rtl/uri.hxx> +#include <svl/zforlist.hxx> #include <cppuhelper/bootstrap.hxx> #include <comphelper/base64.hxx> #include <comphelper/dispatchcommand.hxx> @@ -2092,6 +2093,14 @@ void paintTileIOS(LibreOfficeKitDocument* pThis, } #endif +void setLanguageAndLocale(OUString const & aLangISO) +{ + SvtSysLocaleOptions aLocalOptions; + aLocalOptions.SetLocaleConfigString(aLangISO); + aLocalOptions.SetUILocaleConfigString(aLangISO); + aLocalOptions.Commit(); +} + } // anonymous namespace // Wonder global state ... @@ -2148,13 +2157,17 @@ static LibreOfficeKitDocument* lo_documentLoadWithOptions(LibreOfficeKit* pThis, if (!aLanguage.isEmpty()) { + SfxLokHelper::setDefaultLanguage(aLanguage); + // Set the LOK language tag, used for dialog tunneling. + comphelper::LibreOfficeKit::setLanguageTag(LanguageTag(aLanguage)); + comphelper::LibreOfficeKit::setLocale(LanguageTag(aLanguage)); + + SAL_INFO("lok", "Set document language to " << aLanguage); // use with care - it sets it for the entire core, not just the // document - SvtSysLocaleOptions aSysLocaleOptions; - aSysLocaleOptions.SetLocaleConfigString(aLanguage); - aSysLocaleOptions.SetUILocaleConfigString(aLanguage); - // Set the LOK language tag, used for dialog tunneling. - comphelper::LibreOfficeKit::setLanguageTag(aSysLocaleOptions.GetLanguageTag()); + setLanguageAndLocale(aLanguage); + // Need to reset the static initialized values + SvNumberFormatter::resetTheCurrencyTable(); } uno::Sequence<css::beans::PropertyValue> aFilterOptions(2); @@ -5012,6 +5025,7 @@ static int doc_createViewWithOptions(LibreOfficeKitDocument* pThis, { // Set the LOK language tag, used for dialog tunneling. comphelper::LibreOfficeKit::setLanguageTag(LanguageTag(aLanguage)); + comphelper::LibreOfficeKit::setLocale(LanguageTag(aLanguage)); } int nId = SfxLokHelper::createView(); @@ -5089,7 +5103,9 @@ static void doc_setViewLanguage(SAL_UNUSED_PARAMETER LibreOfficeKitDocument* /*p SolarMutexGuard aGuard; SetLastExceptionMsg(); - SfxLokHelper::setViewLanguage(nId, OStringToOUString(language, RTL_TEXTENCODING_UTF8)); + OUString sLanguage = OStringToOUString(language, RTL_TEXTENCODING_UTF8); + SfxLokHelper::setViewLanguage(nId, sLanguage); + SfxLokHelper::setViewLocale(nId, sLanguage); } @@ -5660,15 +5676,6 @@ static char* lo_getVersionInfo(SAL_UNUSED_PARAMETER LibreOfficeKit* /*pThis*/) return convertOUString(ReplaceStringHookProc(sVersionStrTemplate)); } -static void force_c_locale() -{ - // force locale (and resource files loaded) to en-US - OUString aLangISO("en-US"); - SvtSysLocaleOptions aLocalOptions; - aLocalOptions.SetLocaleConfigString(aLangISO); - aLocalOptions.SetUILocaleConfigString(aLangISO); -} - static void aBasicErrorFunc(const OUString& rError, const OUString& rAction) { OString aBuffer = "Unexpected dialog: " + @@ -6143,7 +6150,7 @@ static int lo_initialize(LibreOfficeKit* pThis, const char* pAppPath, const char Application::ReleaseSolarMutex(); } - force_c_locale(); + setLanguageAndLocale("en-US"); } if (eStage != PRE_INIT) diff --git a/include/comphelper/lok.hxx b/include/comphelper/lok.hxx index 9a01ea2888ad..09d4f682341e 100644 --- a/include/comphelper/lok.hxx +++ b/include/comphelper/lok.hxx @@ -104,8 +104,11 @@ COMPHELPER_DLLPUBLIC bool isViewIdForVisCursorInvalidation(); /// Set whether clients want viewId in visible cursor invalidation payload. COMPHELPER_DLLPUBLIC void setViewIdForVisCursorInvalidation(bool bViewIdForVisCursorInvalidation); -/// Update the current LOK's language. -COMPHELPER_DLLPUBLIC void setLanguageTag(const OUString& lang, bool bCanonicalize = false); +/// Update the current LOK's locale. +COMPHELPER_DLLPUBLIC void setLocale(const LanguageTag& languageTag); +/// Get the current LOK's locale. +COMPHELPER_DLLPUBLIC const LanguageTag& getLocale(); + /// Update the current LOK's language. COMPHELPER_DLLPUBLIC void setLanguageTag(const LanguageTag& languageTag); /// Get the current LOK's language. diff --git a/include/sfx2/lokhelper.hxx b/include/sfx2/lokhelper.hxx index ded6e36cc821..9e91d148e438 100644 --- a/include/sfx2/lokhelper.hxx +++ b/include/sfx2/lokhelper.hxx @@ -54,8 +54,14 @@ public: static std::size_t getViewsCount(); /// Get viewIds of all existing views. static bool getViewIds(int* pArray, size_t nSize); + /// Get the default language that should be used for views + static LanguageTag getDefaultLanguage(); /// Set language of the given view. static void setViewLanguage(int nId, const OUString& rBcp47LanguageTag); + /// Set the default language for views. + static void setDefaultLanguage(const OUString& rBcp47LanguageTag); + /// Set the locale for the given view. + static void setViewLocale(int nId, const OUString& rBcp47LanguageTag); /// Iterate over any view shell, except pThisViewShell, passing it to the f function. template<typename ViewShellType, typename FunctionType> static void forEachOtherView(ViewShellType* pThisViewShell, FunctionType f); diff --git a/include/sfx2/viewsh.hxx b/include/sfx2/viewsh.hxx index d65fae656b16..e81d2db11b7b 100644 --- a/include/sfx2/viewsh.hxx +++ b/include/sfx2/viewsh.hxx @@ -151,6 +151,7 @@ friend class SfxPrinterController; bool bNoNewWindow; bool mbPrinterSettingsModified; LanguageTag maLOKLanguageTag; + LanguageTag maLOKLocale; protected: virtual void Activate(bool IsMDIActivate) override; @@ -346,6 +347,11 @@ public: void SetLOKLanguageTag(const OUString& rBcp47LanguageTag); /// Get the LibreOfficeKit language of this view. const LanguageTag& GetLOKLanguageTag() const { return maLOKLanguageTag; } + + /// Set the LibreOfficeKit locale of this view. + void SetLOKLocale(const OUString& rBcp47LanguageTag); + /// Get the LibreOfficeKit locale of this view. + const LanguageTag& GetLOKLocale() const { return maLOKLocale; } }; diff --git a/include/svl/zforlist.hxx b/include/svl/zforlist.hxx index adbde81c9315..5839c7faa636 100644 --- a/include/svl/zforlist.hxx +++ b/include/svl/zforlist.hxx @@ -722,6 +722,8 @@ public: /// Return the decimal separator matching the given locale / LanguageType. OUString GetLangDecimalSep( LanguageType nLang ) const; + static void resetTheCurrencyTable(); + /// Return a NfCurrencyTable with pointers to <type>NfCurrencyEntry</type> entries static const NfCurrencyTable& GetTheCurrencyTable(); diff --git a/sfx2/source/view/lokhelper.cxx b/sfx2/source/view/lokhelper.cxx index 004b2c58bf90..576c364e72c5 100644 --- a/sfx2/source/view/lokhelper.cxx +++ b/sfx2/source/view/lokhelper.cxx @@ -62,6 +62,11 @@ private: int DisableCallbacks::m_nDisabled = 0; } +namespace +{ +static LanguageTag g_defaultLanguageTag("en-US", true); +} + int SfxLokHelper::createView() { SfxViewFrame* pViewFrame = SfxViewFrame::GetFirst(); @@ -111,8 +116,9 @@ void SfxLokHelper::setView(int nId) { DisableCallbacks dc; - // update the current LOK language for the dialog tunneling + // update the current LOK language and locale for the dialog tunneling comphelper::LibreOfficeKit::setLanguageTag(pViewShell->GetLOKLanguageTag()); + comphelper::LibreOfficeKit::setLocale(pViewShell->GetLOKLocale()); if (pViewShell == SfxViewShell::Current()) return; @@ -165,6 +171,16 @@ bool SfxLokHelper::getViewIds(int* pArray, size_t nSize) return true; } +LanguageTag SfxLokHelper::getDefaultLanguage() +{ + return g_defaultLanguageTag; +} + +void SfxLokHelper::setDefaultLanguage(const OUString& rBcp47LanguageTag) +{ + g_defaultLanguageTag = LanguageTag(rBcp47LanguageTag, true); +} + void SfxLokHelper::setViewLanguage(int nId, const OUString& rBcp47LanguageTag) { SfxViewShellArr_Impl& rViewArr = SfxGetpApp()->GetViewShells_Impl(); @@ -179,6 +195,20 @@ void SfxLokHelper::setViewLanguage(int nId, const OUString& rBcp47LanguageTag) } } +void SfxLokHelper::setViewLocale(int nId, const OUString& rBcp47LanguageTag) +{ + SfxViewShellArr_Impl& rViewArr = SfxGetpApp()->GetViewShells_Impl(); + + for (SfxViewShell* pViewShell : rViewArr) + { + if (pViewShell->GetViewShellId() == ViewShellId(nId)) + { + pViewShell->SetLOKLocale(rBcp47LanguageTag); + return; + } + } +} + static OString lcl_escapeQuotes(const OString &rStr) { if (rStr.getLength() < 1) diff --git a/sfx2/source/view/viewsh.cxx b/sfx2/source/view/viewsh.cxx index 962d94b46d51..0109448d1b79 100644 --- a/sfx2/source/view/viewsh.cxx +++ b/sfx2/source/view/viewsh.cxx @@ -1081,7 +1081,8 @@ SfxViewShell::SfxViewShell , pWindow(nullptr) , bNoNewWindow( nFlags & SfxViewShellFlags::NO_NEWWINDOW ) , mbPrinterSettingsModified(false) -, maLOKLanguageTag("en-US", true) +, maLOKLanguageTag(LANGUAGE_NONE) +, maLOKLocale(LANGUAGE_NONE) { SetMargin( pViewFrame->GetMargin_Impl() ); @@ -1095,6 +1096,9 @@ SfxViewShell::SfxViewShell if (comphelper::LibreOfficeKit::isActive()) { + maLOKLanguageTag = SfxLokHelper::getDefaultLanguage(); + maLOKLocale = SfxLokHelper::getDefaultLanguage(); + vcl::Window* pFrameWin = pViewFrame->GetWindow().GetFrameWindow(); if (pFrameWin && !pFrameWin->GetLOKNotifier()) pFrameWin->SetLOKNotifier(this, true); @@ -1521,6 +1525,11 @@ void SfxViewShell::SetLOKLanguageTag(const OUString& rBcp47LanguageTag) maLOKLanguageTag = aFallbackTag; } +void SfxViewShell::SetLOKLocale(const OUString& rBcp47LanguageTag) +{ + maLOKLocale = LanguageTag(rBcp47LanguageTag, true).makeFallback(); +} + void SfxViewShell::NotifyCursor(SfxViewShell* /*pViewShell*/) const { } diff --git a/svl/source/numbers/zforlist.cxx b/svl/source/numbers/zforlist.cxx index 04e32464d8b2..fd885ac0e16d 100644 --- a/svl/source/numbers/zforlist.cxx +++ b/svl/source/numbers/zforlist.cxx @@ -3404,6 +3404,16 @@ sal_uInt16 SvNumberFormatter::GetYear2000Default() return 1930; } +// static +void SvNumberFormatter::resetTheCurrencyTable() +{ + SAL_INFO("svl", "Resetting the currency table."); + + nSystemCurrencyPosition = 0; + bCurrencyTableInitialized = false; + + GetFormatterRegistry().ConfigurationChanged(nullptr, ConfigurationHints::Locale | ConfigurationHints::Currency | ConfigurationHints::DatePatterns); +} // static const NfCurrencyTable& SvNumberFormatter::GetTheCurrencyTable() diff --git a/unotools/source/misc/syslocale.cxx b/unotools/source/misc/syslocale.cxx index cad884f71d1f..cfb84ffe81f0 100644 --- a/unotools/source/misc/syslocale.cxx +++ b/unotools/source/misc/syslocale.cxx @@ -171,7 +171,7 @@ SvtSysLocaleOptions& SvtSysLocale::GetOptions() const const LanguageTag& SvtSysLocale::GetLanguageTag() const { if (comphelper::LibreOfficeKit::isActive()) - return comphelper::LibreOfficeKit::getLanguageTag(); + return comphelper::LibreOfficeKit::getLocale(); return pImpl->aSysLocaleOptions.GetRealLanguageTag(); } |