diff options
author | Eike Rathke <erack@redhat.com> | 2018-08-22 13:16:19 +0200 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2018-08-22 19:03:27 +0200 |
commit | d0f8daa0980ba8e403b32006831657c5a0a4ea17 (patch) | |
tree | 1baf7f73a6fd5d1c7555403b21e223d7736a9b31 /svl | |
parent | 50c9ed67d29d6105f3907cb7a2fe3322685af53c (diff) |
Resolves: tdf#73063 preserve and roundtrip LCID from/to Excel number formats
Change-Id: I8e3e5ef5873af108596b387e8900d038e3942981
Reviewed-on: https://gerrit.libreoffice.org/59441
Tested-by: Jenkins
Reviewed-by: Eike Rathke <erack@redhat.com>
Diffstat (limited to 'svl')
-rw-r--r-- | svl/source/numbers/zforlist.cxx | 7 | ||||
-rw-r--r-- | svl/source/numbers/zformat.cxx | 27 |
2 files changed, 31 insertions, 3 deletions
diff --git a/svl/source/numbers/zforlist.cxx b/svl/source/numbers/zforlist.cxx index 9d4a630df51b..023bc3788793 100644 --- a/svl/source/numbers/zforlist.cxx +++ b/svl/source/numbers/zforlist.cxx @@ -811,9 +811,13 @@ OUString SvNumberFormatter::GetFormatStringForExcel( sal_uInt32 nKey, const NfKe } else { + bool bSystemLanguage = false; LanguageType nLang = pEntry->GetLanguage(); if (nLang == LANGUAGE_SYSTEM) + { + bSystemLanguage = true; nLang = SvtSysLocale().GetLanguageTag().getLanguageType(); + } if (nLang != LANGUAGE_ENGLISH_US) { sal_Int32 nCheckPos; @@ -833,7 +837,8 @@ OUString SvNumberFormatter::GetFormatStringForExcel( sal_uInt32 nKey, const NfKe // before (which doesn't do anything if it was the same locale // already). rTempFormatter.ChangeIntl( LANGUAGE_ENGLISH_US); - aFormatStr = pEntry->GetMappedFormatstring( rKeywords, *rTempFormatter.GetLocaleData(), nLang ); + aFormatStr = pEntry->GetMappedFormatstring( rKeywords, *rTempFormatter.GetLocaleData(), nLang, + bSystemLanguage); } } } diff --git a/svl/source/numbers/zformat.cxx b/svl/source/numbers/zformat.cxx index 1d591f6e5dff..3d7e1c42bd8e 100644 --- a/svl/source/numbers/zformat.cxx +++ b/svl/source/numbers/zformat.cxx @@ -1042,6 +1042,10 @@ SvNumberformat::SvNumberformat(OUString& rString, } else { + if (nIndex == 0) + // Locale data not available, remember. + maLocale.meLanguageWithoutLocaleData = aTmpLocale.meLanguage; + sStr = "$-" + aTmpLocale.generateCode(); } NumFor[nIndex].SetNatNumLang( MsLangId::getRealLanguage( aTmpLocale.meLanguage)); @@ -1497,7 +1501,9 @@ OUString SvNumberformat::LocaleType::generateCode() const } #endif - sal_uInt16 n16 = static_cast<sal_uInt16>(meLanguage); + sal_uInt16 n16 = static_cast<sal_uInt16>( + (meLanguageWithoutLocaleData == LANGUAGE_DONTKNOW) ? meLanguage : + meLanguageWithoutLocaleData); if (meLanguage == LANGUAGE_SYSTEM) { switch (meSubstitute) @@ -1529,6 +1535,7 @@ OUString SvNumberformat::LocaleType::generateCode() const SvNumberformat::LocaleType::LocaleType() : meLanguage(LANGUAGE_DONTKNOW) + , meLanguageWithoutLocaleData(LANGUAGE_DONTKNOW) , meSubstitute(Substitute::NONE) , mnNumeralShape(0) , mnCalendarType(0) @@ -1537,6 +1544,7 @@ SvNumberformat::LocaleType::LocaleType() SvNumberformat::LocaleType::LocaleType(sal_uInt32 nRawNum) : meLanguage(LANGUAGE_DONTKNOW) + , meLanguageWithoutLocaleData(LANGUAGE_DONTKNOW) , meSubstitute(Substitute::NONE) , mnNumeralShape(0) , mnCalendarType(0) @@ -5068,7 +5076,8 @@ void lcl_incrementAlphabetWithNatNum ( sal_uInt32& nAlphabetID, sal_uInt32 nNatN OUString SvNumberformat::GetMappedFormatstring( const NfKeywordTable& rKeywords, const LocaleDataWrapper& rLocWrp, - LanguageType nOriginalLang /* =LANGUAGE_DONTKNOW */ ) const + LanguageType nOriginalLang /* =LANGUAGE_DONTKNOW */, + bool bSystemLanguage /* =false */ ) const { OUStringBuffer aStr; if (maLocale.meSubstitute != LocaleType::Substitute::NONE) @@ -5385,6 +5394,20 @@ OUString SvNumberformat::GetMappedFormatstring( const NfKeywordTable& rKeywords, if ( aNatNum.GetDBNum() > 0 && nLanguageID == LANGUAGE_SYSTEM ) nLanguageID = MsLangId::getRealLanguage( aNatNum.GetLang()); } + else if (!bSystemLanguage && nOriginalLang != LANGUAGE_DONTKNOW) + { + // Explicit locale, write only to the first subformat. + if (n == 0) + nLanguageID = MsLangId::getRealLanguage( nOriginalLang); + } + else if (bSystemLanguage && maLocale.meLanguageWithoutLocaleData != LANGUAGE_DONTKNOW) + { + // Explicit locale but no locale data thus assigned to system + // locale, preserve for roundtrip, write only to the first + // subformat. + if (n == 0) + nLanguageID = maLocale.meLanguageWithoutLocaleData; + } if ( nCalendarID > 0 ) { // Add alphabet and language to calendar if ( nAlphabetID == 0 ) |