From 7dc49d024c23ef2b4a41484427a4dd18e6690756 Mon Sep 17 00:00:00 2001 From: Michael Stahl Date: Thu, 19 May 2022 13:23:33 +0200 Subject: sw: language fallback in MSWordExportBase::GetNumberFormat() There is this number format: . . in a paragraph which has fo:language="zxx", so the field has LANGUAGE_NONE. MSWordExportBase::GetNumberFormat() exports as: DATE \@"dd/MM/yyyy" But should be: DATE \@"dd.MM.yyyy" Follow Eike's suggestion to use the number format's language in case the field doesn't have one. Change-Id: I596bea5daa75c717931b3c5d5506103b87b8ee08 --- svl/qa/unit/svl.cxx | 15 ++++++++++++++- sw/source/filter/ww8/ww8atr.cxx | 5 +++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/svl/qa/unit/svl.cxx b/svl/qa/unit/svl.cxx index d30a7b6279ec..4304875b8088 100644 --- a/svl/qa/unit/svl.cxx +++ b/svl/qa/unit/svl.cxx @@ -90,7 +90,7 @@ public: CPPUNIT_TEST(testExcelExportFormats); CPPUNIT_TEST_SUITE_END(); -private: +protected: uno::Reference< uno::XComponentContext > m_xContext; void checkPreviewString(SvNumberFormatter& aFormatter, const OUString& sCode, @@ -1728,6 +1728,19 @@ void Test::testExcelExportFormats() CPPUNIT_ASSERT_EQUAL( OUString("[$R-1C09]\\ #,##0.0;[$R-1C09]\\-#,##0.0"), aCode); } +CPPUNIT_TEST_FIXTURE(Test, testLanguageNone) +{ + SvNumberFormatter aFormatter(m_xContext, LANGUAGE_ENGLISH_US); + NfKeywordTable keywords; + aFormatter.FillKeywordTableForExcel(keywords); + OUString code("TT.MM.JJJJ"); + sal_uInt32 nKey = aFormatter.GetEntryKey(code, LANGUAGE_GERMAN); + CPPUNIT_ASSERT(nKey != NUMBERFORMAT_ENTRY_NOT_FOUND); + SvNumberformat const*const pFormat = aFormatter.GetEntry(nKey); + LocaleDataWrapper ldw(m_xContext, LanguageTag(pFormat->GetLanguage())); + CPPUNIT_ASSERT_EQUAL(OUString("dd.mm.yyyy"), pFormat->GetMappedFormatstring(keywords, ldw)); +} + CPPUNIT_TEST_SUITE_REGISTRATION(Test); } diff --git a/sw/source/filter/ww8/ww8atr.cxx b/sw/source/filter/ww8/ww8atr.cxx index b2c3b35d7ae1..1327f78d645a 100644 --- a/sw/source/filter/ww8/ww8atr.cxx +++ b/sw/source/filter/ww8/ww8atr.cxx @@ -2581,6 +2581,11 @@ bool MSWordExportBase::GetNumberFormat(const SwField& rField, OUString& rStr) if( pNumFormat ) { LanguageType nLng = rField.GetLanguage(); + SAL_WARN_IF(nLng == LANGUAGE_DONTKNOW, "sw.ww8", "unexpected LANGUAGE_DONTKNOW"); + if (nLng == LANGUAGE_NONE || nLng == LANGUAGE_DONTKNOW) + { + nLng = pNumFormat->GetLanguage(); + } LocaleDataWrapper aLocDat(pNFormatr->GetComponentContext(), LanguageTag(nLng)); -- cgit v1.2.3