[Libreoffice-commits] core.git: i18nlangtag/source include/i18nlangtag xmloff/source
Eike Rathke
erack at redhat.com
Wed Jul 10 06:59:41 PDT 2013
i18nlangtag/source/languagetag/languagetag.cxx | 21 +++++++++++++--------
include/i18nlangtag/languagetag.hxx | 12 ++++++------
xmloff/source/core/xmlexp.cxx | 8 ++++----
xmloff/source/style/chrlohdl.cxx | 19 +++++++++++--------
4 files changed, 34 insertions(+), 26 deletions(-)
New commits:
commit 1e744d5d9de568aeef6794365dc6f2bf84537ddb
Author: Eike Rathke <erack at redhat.com>
Date: Wed Jul 10 15:57:25 2013 +0200
changed getIsoLanguageCountry() to getIsoLanguageScriptCountry()
And don't write ODF *:script if *:language is not written either.
Change-Id: If6d49cc6fbb8d566cc59edf35ed7991d57d941c0
diff --git a/i18nlangtag/source/languagetag/languagetag.cxx b/i18nlangtag/source/languagetag/languagetag.cxx
index 7d47580..13e25f8 100644
--- a/i18nlangtag/source/languagetag/languagetag.cxx
+++ b/i18nlangtag/source/languagetag/languagetag.cxx
@@ -877,17 +877,22 @@ LanguageType LanguageTag::getLanguageType( bool bResolveSystem ) const
}
-void LanguageTag::getIsoLanguageCountry( OUString& rLanguage, OUString& rCountry ) const
+void LanguageTag::getIsoLanguageScriptCountry( OUString& rLanguage, OUString& rScript, OUString& rCountry ) const
{
- if (!isIsoLocale())
+ // Calling isIsoODF() first is a predicate for getLanguage(), getScript()
+ // and getCountry() to work correctly in this context.
+ if (isIsoODF())
{
- rLanguage = OUString();
- rCountry = OUString();
- return;
+ rLanguage = getLanguage();
+ rScript = getScript();
+ rCountry = getCountry();
+ }
+ else
+ {
+ rLanguage = (isIsoLanguage( getLanguage()) ? getLanguage() : OUString());
+ rScript = (isIsoScript( getScript()) ? getScript() : OUString());
+ rCountry = (isIsoCountry( getCountry()) ? getCountry() : OUString());
}
- // After isIsoLocale() it's safe to call getLanguage() for ISO code.
- rLanguage = getLanguage();
- rCountry = getCountry();
}
diff --git a/include/i18nlangtag/languagetag.hxx b/include/i18nlangtag/languagetag.hxx
index 8f23098..d779f9d 100644
--- a/include/i18nlangtag/languagetag.hxx
+++ b/include/i18nlangtag/languagetag.hxx
@@ -128,20 +128,20 @@ public:
*/
LanguageType getLanguageType( bool bResolveSystem = true ) const;
- /** Obtain ISO strings for language and country.
+ /** Obtain ISO strings for language, script and country.
- This is a convenience method for places that so far use only language and
- country to replace the MsLangId::convert...IsoNames...() calls. Avoid
- use in new code.
+ This is a convenience method for ODF export places only. Avoid use in
+ other code.
ATTENTION! May return empty strings if the language tag is not
expressable in valid ISO codes!
- @see isIsoLocale()
+ @see isIsoODF()
Always resolves an empty tag to the system locale.
*/
- void getIsoLanguageCountry( OUString& rLanguage, OUString& rCountry ) const;
+ void getIsoLanguageScriptCountry( OUString& rLanguage,
+ OUString& rScript, OUString& rCountry ) const;
/** Get ISO 639 language code, or BCP 47 language.
diff --git a/xmloff/source/core/xmlexp.cxx b/xmloff/source/core/xmlexp.cxx
index 357999b..3c22c8f 100644
--- a/xmloff/source/core/xmlexp.cxx
+++ b/xmloff/source/core/xmlexp.cxx
@@ -1113,13 +1113,13 @@ void SvXMLExport::AddLanguageTagAttributes( sal_uInt16 nPrefix, sal_uInt16 nPref
// for consumers not handling *:rfc-language-tag, ensuring that only
// valid ISO codes are stored. Here the bWriteEmpty parameter has no
// meaning.
- OUString aLanguage, aCountry;
- rLanguageTag.getIsoLanguageCountry( aLanguage, aCountry);
+ OUString aLanguage, aScript, aCountry;
+ rLanguageTag.getIsoLanguageScriptCountry( aLanguage, aScript, aCountry);
if (!aLanguage.isEmpty())
{
AddAttribute( nPrefix, eLanguage, aLanguage);
- if (rLanguageTag.hasScript())
- AddAttribute( nPrefix, eScript, rLanguageTag.getScript());
+ if (!aScript.isEmpty())
+ AddAttribute( nPrefix, eScript, aScript);
if (!aCountry.isEmpty())
AddAttribute( nPrefix, eCountry, aCountry);
}
diff --git a/xmloff/source/style/chrlohdl.cxx b/xmloff/source/style/chrlohdl.cxx
index 4a0ee09..d23159d 100644
--- a/xmloff/source/style/chrlohdl.cxx
+++ b/xmloff/source/style/chrlohdl.cxx
@@ -115,8 +115,8 @@ sal_Bool XMLCharLanguageHdl::exportXML( OUString& rStrExpValue, const uno::Any&
else
{
LanguageTag aLanguageTag( aLocale);
- OUString aCountry;
- aLanguageTag.getIsoLanguageCountry( rStrExpValue, aCountry);
+ OUString aScript, aCountry;
+ aLanguageTag.getIsoLanguageScriptCountry( rStrExpValue, aScript, aCountry);
// Do not write *:language='none' for a non-ISO language with
// *:rfc-language-tag that is written if Variant is not empty. If there
// is no match do not write this attribute at all.
@@ -235,10 +235,13 @@ sal_Bool XMLCharScriptHdl::exportXML( OUString& rStrExpValue, const uno::Any& rV
if (!aLanguageTag.hasScript())
return sal_False;
- rStrExpValue = aLanguageTag.getScript();
-
- if( rStrExpValue.isEmpty() )
- rStrExpValue = GetXMLToken( XML_NONE );
+ OUString aLanguage, aCountry;
+ aLanguageTag.getIsoLanguageScriptCountry( aLanguage, rStrExpValue, aCountry);
+ // For non-ISO language it does not make sense to write *:script if
+ // *:language is not written either, does it? It's all in
+ // *:rfc-language-tag
+ if (aLanguage.isEmpty() || rStrExpValue.isEmpty())
+ return sal_False;
return sal_True;
}
@@ -301,8 +304,8 @@ sal_Bool XMLCharCountryHdl::exportXML( OUString& rStrExpValue, const uno::Any& r
else
{
LanguageTag aLanguageTag( aLocale);
- OUString aLanguage;
- aLanguageTag.getIsoLanguageCountry( aLanguage, rStrExpValue);
+ OUString aLanguage, aScript;
+ aLanguageTag.getIsoLanguageScriptCountry( aLanguage, aScript, rStrExpValue);
// Do not write *:country='none' for a non-ISO country with
// *:rfc-language-tag that is written if Variant is not empty. If there
// is no match do not write this attribute at all.
More information about the Libreoffice-commits
mailing list