[Libreoffice-commits] core.git: sw/inc sw/qa sw/source

Miklos Vajna (via logerrit) logerrit at kemper.freedesktop.org
Fri Sep 4 16:01:12 UTC 2020


 sw/inc/doc.hxx                                      |    2 +
 sw/qa/core/doc/data/locale-independent-template.odt |binary
 sw/qa/core/doc/doc.cxx                              |   22 ++++++++++++++++++++
 sw/source/core/doc/doc.cxx                          |    5 ++++
 sw/source/core/doc/docnew.cxx                       |   22 ++++++++++++++++++++
 5 files changed, 51 insertions(+)

New commits:
commit 7d379bd8535b32a8d63a5fa8131cd9e82c7ff94f
Author:     Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Fri Sep 4 16:51:59 2020 +0200
Commit:     Miklos Vajna <vmiklos at collabora.com>
CommitDate: Fri Sep 4 18:00:29 2020 +0200

    sw: default to UI locale when language is missing
    
    This means that when extras/source/shellnew/soffice.odt is opened, it'll
    always match the user's language. The same was already working in Calc
    and Impress.
    
    Change-Id: Ic1afc82d7b59f1bd32815586f756e7e8408e5c6b
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/102051
    Reviewed-by: Miklos Vajna <vmiklos at collabora.com>
    Tested-by: Jenkins

diff --git a/sw/inc/doc.hxx b/sw/inc/doc.hxx
index ba8c67e3521c..aff7d10e0ce3 100644
--- a/sw/inc/doc.hxx
+++ b/sw/inc/doc.hxx
@@ -1653,6 +1653,8 @@ public:
     /// Returns true if no dictionary can be found for any content
     bool IsDictionaryMissing() const { return meDictionaryMissing == MissingDictionary::True; }
 
+    void SetLanguage(const LanguageType eLang, const sal_uInt16 nId);
+
 private:
     // Copies master header to left / first one, if necessary - used by ChgPageDesc().
     void CopyMasterHeader(const SwPageDesc &rChged, const SwFormatHeader &rHead, SwPageDesc &pDesc, bool bLeft, bool bFirst);
diff --git a/sw/qa/core/doc/data/locale-independent-template.odt b/sw/qa/core/doc/data/locale-independent-template.odt
new file mode 100644
index 000000000000..d2a8dc274c6c
Binary files /dev/null and b/sw/qa/core/doc/data/locale-independent-template.odt differ
diff --git a/sw/qa/core/doc/doc.cxx b/sw/qa/core/doc/doc.cxx
index bd419d1f8b16..f3bb4508189b 100644
--- a/sw/qa/core/doc/doc.cxx
+++ b/sw/qa/core/doc/doc.cxx
@@ -15,6 +15,7 @@
 #include <editeng/frmdiritem.hxx>
 #include <vcl/errinf.hxx>
 #include <vcl/event.hxx>
+#include <editeng/langitem.hxx>
 
 #include <wrtsh.hxx>
 #include <fmtanchr.hxx>
@@ -89,6 +90,27 @@ CPPUNIT_TEST_FIXTURE(SwCoreDocTest, testNumDownIndent)
     // - Actual  : B
     // i.e. pressing <tab> at the start of the paragraph did not change the layout.
     CPPUNIT_ASSERT_EQUAL(OUString("\tB"), pTextNode->GetText());
+    ErrorRegistry::Reset();
+}
+
+CPPUNIT_TEST_FIXTURE(SwCoreDocTest, testLocaleIndependentTemplate)
+{
+    SwDoc* pDoc = createSwDoc(DATA_DIRECTORY, "locale-independent-template.odt");
+    SwDocShell* pDocShell = pDoc->GetDocShell();
+    SwWrtShell* pWrtShell = pDocShell->GetWrtShell();
+    SfxItemSet aSet(pWrtShell->GetAttrPool(), { { RES_CHRATR_LANGUAGE, RES_CHRATR_LANGUAGE } });
+    pWrtShell->GetCurAttr(aSet);
+    const SvxLanguageItem* pItem = aSet.GetItem(RES_CHRATR_LANGUAGE);
+    CPPUNIT_ASSERT(pItem);
+    LanguageType eLang = pItem->GetValue();
+
+    // Without the accompanying fix in place, this test would have failed with:
+    // - Expected: 1033 (LANGUAGE_ENGLISH_US)
+    // - Actual  : 1023 (LANGUAGE_DONTKNOW)
+    // i.e. the status bar and the format -> character dialog didn't fall back to the UI locale when
+    // an explicit language was not set for the document.
+    CPPUNIT_ASSERT_EQUAL(LANGUAGE_ENGLISH_US, eLang);
+    ErrorRegistry::Reset();
 }
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sw/source/core/doc/doc.cxx b/sw/source/core/doc/doc.cxx
index 005927fbee51..a1f9ed152a46 100644
--- a/sw/source/core/doc/doc.cxx
+++ b/sw/source/core/doc/doc.cxx
@@ -93,6 +93,7 @@
 #include <osl/diagnose.h>
 #include <osl/interlck.h>
 #include <vbahelper/vbaaccesshelper.hxx>
+#include <editeng/langitem.hxx>
 #include <calbck.hxx>
 #include <crsrsh.hxx>
 
@@ -1826,5 +1827,9 @@ void SwDoc::SetMissingDictionaries( bool bIsMissing )
         meDictionaryMissing = MissingDictionary::True;
 };
 
+void SwDoc::SetLanguage(const LanguageType eLang, const sal_uInt16 nId)
+{
+    mpAttrPool->SetPoolDefaultItem(SvxLanguageItem(eLang, nId));
+}
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/doc/docnew.cxx b/sw/source/core/doc/docnew.cxx
index 70961797a7e6..8d61f215e602 100644
--- a/sw/source/core/doc/docnew.cxx
+++ b/sw/source/core/doc/docnew.cxx
@@ -26,6 +26,7 @@
 #include <com/sun/star/text/XFlatParagraphIteratorProvider.hpp>
 #include <com/sun/star/linguistic2/XProofreadingIterator.hpp>
 #include <com/sun/star/frame/XModel.hpp>
+#include <com/sun/star/i18n/ScriptType.hpp>
 
 #include <comphelper/processfactory.hxx>
 #include <comphelper/random.hxx>
@@ -100,6 +101,9 @@
 #include <fmtmeta.hxx>
 
 #include <svx/xfillit0.hxx>
+#include <unotools/configmgr.hxx>
+#include <i18nlangtag/mslangid.hxx>
+#include <editeng/langitem.hxx>
 
 using namespace ::com::sun::star;
 using namespace ::com::sun::star::document;
@@ -357,6 +361,24 @@ SwDoc::SwDoc()
     }
     mnRsidRoot = mnRsid;
 
+    if (!utl::ConfigManager::IsFuzzing())
+    {
+        // Make sure that in case the document language is not set, then we don't return
+        // LANGUAGE_DONTKNOW, but the UI locale.
+        const SvtLinguConfig aLinguConfig;
+        SvtLinguOptions aOptions;
+        aLinguConfig.GetOptions(aOptions);
+        LanguageType eLang = MsLangId::resolveSystemLanguageByScriptType(aOptions.nDefaultLanguage,
+                                                                         i18n::ScriptType::LATIN);
+        SetLanguage(eLang, RES_CHRATR_LANGUAGE);
+        eLang = MsLangId::resolveSystemLanguageByScriptType(aOptions.nDefaultLanguage_CJK,
+                                                            i18n::ScriptType::ASIAN);
+        SetLanguage(eLang, RES_CHRATR_CJK_LANGUAGE);
+        eLang = MsLangId::resolveSystemLanguageByScriptType(aOptions.nDefaultLanguage_CTL,
+                                                            i18n::ScriptType::COMPLEX);
+        SetLanguage(eLang, RES_CHRATR_CTL_LANGUAGE);
+    }
+
     getIDocumentState().ResetModified();
 }
 


More information about the Libreoffice-commits mailing list