write bcp47 format-locale if necessary and read both

Change-Id: I82cfdd8652d1c86b701ccb0b913928c860a360d2
This commit is contained in:
Eike Rathke
2013-07-12 12:29:45 +02:00
parent 76d36d5bba
commit 6c88ebe9aa
3 changed files with 24 additions and 15 deletions

View File

@@ -21,6 +21,7 @@ $(eval $(call gb_Library_use_libraries,xmlscript,\
cppuhelper \
sal \
tl \
i18nlangtag \
$(gb_UWINAPI) \
))

View File

@@ -58,6 +58,7 @@
#include <com/sun/star/document/GraphicObjectResolver.hpp>
#include <comphelper/processfactory.hxx>
#include <i18nlangtag/languagetag.hxx>
using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;
@@ -485,19 +486,22 @@ void ElementDescriptor::addNumberFormatAttr(
addAttribute(XMLNS_DIALOGS_PREFIX ":format-code", sFormat );
// format-locale
OUStringBuffer buf( 48 );
buf.append( locale.Language );
if (!locale.Country.isEmpty())
LanguageTag aLanguageTag( locale);
OUString aStr;
if (aLanguageTag.isIsoLocale())
{
buf.append( (sal_Unicode)';' );
buf.append( locale.Country );
if (!locale.Variant.isEmpty())
{
buf.append( (sal_Unicode)';' );
buf.append( locale.Variant );
}
// Old style "lll;CC" for compatibility, I really don't know what may
// consume this.
if (aLanguageTag.getCountry().isEmpty())
aStr = aLanguageTag.getLanguage();
else
aStr = aLanguageTag.getLanguage() + ";" + aLanguageTag.getCountry();
}
addAttribute( XMLNS_DIALOGS_PREFIX ":format-locale", buf.makeStringAndClear() );
else
{
aStr = aLanguageTag.getBcp47( false);
}
addAttribute( XMLNS_DIALOGS_PREFIX ":format-locale", aStr );
}
//__________________________________________________________________________________________________
Any ElementDescriptor::readProp( OUString const & rPropName )

View File

@@ -31,6 +31,7 @@
#include <com/sun/star/script/vba/XVBACompatibility.hpp>
#include <comphelper/processfactory.hxx>
#include <i18nlangtag/languagetag.hxx>
using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;
@@ -539,21 +540,24 @@ void FormattedFieldElement::endElement()
if (!sLocale.isEmpty())
{
// split locale
// Don't know what may have written what we read here, so parse all
// old style including the trailing ";Variant" if present.
sal_Int32 semi0 = sLocale.indexOf( ';' );
if (semi0 < 0) // no semi at all, just try language
if (semi0 < 0) // no semi at all, try new BCP47 or just language
{
locale.Language = sLocale;
locale = LanguageTag( sLocale).getLocale( false);
}
else
{
sal_Int32 semi1 = sLocale.indexOf( ';', semi0 +1 );
if (semi1 > semi0) // language;country;variant
{
SAL_WARN( "xmlscript.xmldlg", "format-locale with variant that is ignored: " << sLocale);
locale.Language = sLocale.copy( 0, semi0 );
locale.Country = sLocale.copy( semi0 +1, semi1 - semi0 -1 );
locale.Variant = sLocale.copy( semi1 +1 );
// Ignore Variant that no one knows what it would be.
}
else // try language;country
else // language;country
{
locale.Language = sLocale.copy( 0, semi0 );
locale.Country = sLocale.copy( semi0 +1 );