Rebased ref, commits from common ancestor:
commit 712b7e578292e521c64e6de117dbf7d11e38ba7a
Author: Michael Stahl <[email protected]>
AuthorDate: Thu May 19 13:23:33 2022 +0200
Commit: Michael Stahl <[email protected]>
CommitDate: Fri May 20 10:42:31 2022 +0200
svl: SvNumberformat::GetMappedFormatstring() vs. LANGUAGE_DONTKNOW
There is this number format:
<number:date-style style:name="N36" number:automatic-order="true">
<number:day number:style="long"/>
<number:text>.</number:text>
<number:month number:style="long"/>
<number:text>.</number:text>
<number:year number:style="long"/>
</number:date-style>
MSWordExportBase::GetNumberFormat() exports as: DATE \@"dd/MM/yyyy"
But should be: DATE \@"dd.MM.yyyy"
The problem is that with LANGUAGE_DONTKNOW, the available
LocaleDataWrapper can't be considered reliable, so prefer to use the
existing separator string in this case.
Change-Id: I596bea5daa75c717931b3c5d5506103b87b8ee08
diff --git a/svl/qa/unit/svl.cxx b/svl/qa/unit/svl.cxx
index d30a7b6279ec..2e4f21099d0d 100644
--- a/svl/qa/unit/svl.cxx
+++ b/svl/qa/unit/svl.cxx
@@ -34,6 +34,7 @@
#include <svl/sharedstring.hxx>
#include <tools/color.hxx>
#include <unotools/syslocale.hxx>
+#include <unotest/bootstrapfixturebase.hxx> // for CPPUNIT_TEST_FIXTURE
#include <memory>
#include <unicode/timezone.h>
@@ -90,7 +91,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 +1729,19 @@ void Test::testExcelExportFormats()
CPPUNIT_ASSERT_EQUAL( OUString("[$R-1C09]\\ #,##0.0;[$R-1C09]\\-#,##0.0"),
aCode);
}
+CPPUNIT_TEST_FIXTURE(Test, testLanguageDontknow)
+{
+ 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(LANGUAGE_DONTKNOW));
+ CPPUNIT_ASSERT_EQUAL(OUString("dd.mm.yyyy"),
pFormat->GetMappedFormatstring(keywords, ldw));
+}
+
CPPUNIT_TEST_SUITE_REGISTRATION(Test);
}
diff --git a/svl/source/numbers/zformat.cxx b/svl/source/numbers/zformat.cxx
index 23c0919aecf2..acbea945cd88 100644
--- a/svl/source/numbers/zformat.cxx
+++ b/svl/source/numbers/zformat.cxx
@@ -5291,7 +5291,14 @@ OUString SvNumberformat::GetMappedFormatstring( const
NfKeywordTable& rKeywords,
aStr.append( "-" );
break;
case NF_SYMBOLTYPE_DATESEP :
- aStr.append( rLocWrp.getDateSep() );
+ if (nOriginalLang == LANGUAGE_DONTKNOW)
+ { // prefer whatever the existing separator is
+ aStr.append(rStrArray[j]);
+ }
+ else
+ {
+ aStr.append( rLocWrp.getDateSep() );
+ }
break;
case NF_SYMBOLTYPE_TIMESEP :
aStr.append( rLocWrp.getTimeSep() );