diff options
-rw-r--r-- | sw/inc/doc.hxx | 2 | ||||
-rw-r--r-- | sw/qa/core/doc/data/locale-independent-template.odt | bin | 0 -> 642 bytes | |||
-rw-r--r-- | sw/qa/core/doc/doc.cxx | 22 | ||||
-rw-r--r-- | sw/source/core/doc/doc.cxx | 5 | ||||
-rw-r--r-- | sw/source/core/doc/docnew.cxx | 22 |
5 files changed, 51 insertions, 0 deletions
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 Binary files differnew file mode 100644 index 000000000000..d2a8dc274c6c --- /dev/null +++ b/sw/qa/core/doc/data/locale-independent-template.odt 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(); } |