[Libreoffice-commits] core.git: comphelper/source desktop/CppunitTest_desktop_lib.mk desktop/qa desktop/source include/comphelper include/sfx2 include/svl sfx2/source svl/source unotools/source

Tomaž Vajngerl (via logerrit) logerrit at kemper.freedesktop.org
Tue Feb 25 08:26:05 UTC 2020


 comphelper/source/misc/lok.cxx              |   73 ++++++++++++++++++++++++----
 desktop/CppunitTest_desktop_lib.mk          |    1 
 desktop/qa/desktop_lib/test_desktop_lib.cxx |    2 
 desktop/source/lib/init.cxx                 |   39 ++++++++------
 include/comphelper/lok.hxx                  |    7 +-
 include/sfx2/lokhelper.hxx                  |    6 ++
 include/sfx2/viewsh.hxx                     |    6 ++
 include/svl/zforlist.hxx                    |    2 
 sfx2/source/view/lokhelper.cxx              |   32 +++++++++++-
 sfx2/source/view/viewsh.cxx                 |   11 +++-
 svl/source/numbers/zforlist.cxx             |   10 +++
 unotools/source/misc/syslocale.cxx          |    2 
 12 files changed, 159 insertions(+), 32 deletions(-)

New commits:
commit 3810f28d784ff71d4c6d68557e70bd80c1d1d99c
Author:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Mon Feb 24 08:07:12 2020 +0100
Commit:     Andras Timar <andras.timar at collabora.com>
CommitDate: Tue Feb 25 09:25:33 2020 +0100

    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 at gmail.com>
    Reviewed-by: Andras Timar <andras.timar at collabora.com>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/89343
    Tested-by: Jenkins

diff --git a/comphelper/source/misc/lok.cxx b/comphelper/source/misc/lok.cxx
index f339db2657dc..2deb105d8e02 100644
--- a/comphelper/source/misc/lok.cxx
+++ b/comphelper/source/misc/lok.cxx
@@ -35,7 +35,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);
@@ -153,23 +201,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 a582ba764a01..4e2aac986fcb 100644
--- a/desktop/qa/desktop_lib/test_desktop_lib.cxx
+++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx
@@ -2764,7 +2764,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 8c7ac75e6b80..65776dc3f1fb 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>
@@ -2078,6 +2079,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 ...
@@ -2134,13 +2143,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);
@@ -4885,6 +4898,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();
@@ -4962,7 +4976,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);
 }
 
 
@@ -5508,15 +5524,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: " +
@@ -5987,7 +5994,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 53ee43f498db..ca875b8df4a2 100644
--- a/include/comphelper/lok.hxx
+++ b/include/comphelper/lok.hxx
@@ -94,8 +94,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 c05920f548ac..f87432c792b8 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 22689aa88c3d..e4bf851690f1 100644
--- a/include/svl/zforlist.hxx
+++ b/include/svl/zforlist.hxx
@@ -730,6 +730,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 5556caa26be3..f924ca8edaf4 100644
--- a/sfx2/source/view/lokhelper.cxx
+++ b/sfx2/source/view/lokhelper.cxx
@@ -63,6 +63,11 @@ private:
 int DisableCallbacks::m_nDisabled = 0;
 }
 
+namespace
+{
+static LanguageTag g_defaultLanguageTag("en-US", true);
+}
+
 int SfxLokHelper::createView()
 {
     SfxViewFrame* pViewFrame = SfxViewFrame::GetFirst();
@@ -112,8 +117,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;
@@ -166,6 +172,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();
@@ -180,6 +196,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 10f149dff58a..a28dc663ade9 100644
--- a/sfx2/source/view/viewsh.cxx
+++ b/sfx2/source/view/viewsh.cxx
@@ -1069,7 +1069,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() );
@@ -1083,6 +1084,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);
@@ -1506,6 +1510,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 1e7738caaf20..21886b25d04e 100644
--- a/svl/source/numbers/zforlist.cxx
+++ b/svl/source/numbers/zforlist.cxx
@@ -3413,6 +3413,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 b80a89aff396..7f89d34f3946 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();
 }


More information about the Libreoffice-commits mailing list