summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2020-09-04 16:51:59 +0200
committerMiklos Vajna <vmiklos@collabora.com>2020-09-07 09:07:52 +0200
commit94ebfe7ae7ba7608d2db6359f7a77328781f37d1 (patch)
tree3f3cee45cdabdbd7bb97825d77282324c8982315 /sw
parente46a0fa97f5cf31dbf302e44bdcc6f05139f61dd (diff)
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. Conflicts: sw/source/core/doc/docnew.cxx Change-Id: Ic1afc82d7b59f1bd32815586f756e7e8408e5c6b Reviewed-on: https://gerrit.libreoffice.org/c/core/+/102052 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com> Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Diffstat (limited to 'sw')
-rw-r--r--sw/inc/doc.hxx2
-rw-r--r--sw/qa/core/doc/data/locale-independent-template.odtbin0 -> 642 bytes
-rw-r--r--sw/qa/core/doc/doc.cxx22
-rw-r--r--sw/source/core/doc/doc.cxx5
-rw-r--r--sw/source/core/doc/docnew.cxx22
5 files changed, 51 insertions, 0 deletions
diff --git a/sw/inc/doc.hxx b/sw/inc/doc.hxx
index cc06333cc51b..fab3d74159f6 100644
--- a/sw/inc/doc.hxx
+++ b/sw/inc/doc.hxx
@@ -1654,6 +1654,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
--- /dev/null
+++ b/sw/qa/core/doc/data/locale-independent-template.odt
Binary files differ
diff --git a/sw/qa/core/doc/doc.cxx b/sw/qa/core/doc/doc.cxx
index 80f338042281..d30cbe47cc3b 100644
--- a/sw/qa/core/doc/doc.cxx
+++ b/sw/qa/core/doc/doc.cxx
@@ -16,6 +16,7 @@
#include <editeng/frmdiritem.hxx>
#include <vcl/errinf.hxx>
#include <vcl/event.hxx>
+#include <editeng/langitem.hxx>
#include <wrtsh.hxx>
#include <fmtanchr.hxx>
@@ -102,6 +103,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 = createDoc("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 246ffc1a5c8a..5773a60d3d2a 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>
@@ -1845,5 +1846,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 f3e7aa8e1ea6..70e5b1507950 100644
--- a/sw/source/core/doc/docnew.cxx
+++ b/sw/source/core/doc/docnew.cxx
@@ -25,6 +25,7 @@
#include <proofreadingiterator.hxx>
#include <com/sun/star/text/XFlatParagraphIteratorProvider.hpp>
#include <com/sun/star/linguistic2/XProofreadingIterator.hpp>
+#include <com/sun/star/i18n/ScriptType.hpp>
#include <comphelper/processfactory.hxx>
#include <comphelper/random.hxx>
@@ -98,6 +99,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;
@@ -355,6 +359,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();
}