[Libreoffice-commits] core.git: 8 commits - i18nlangtag/qa i18nlangtag/source include/i18nlangtag
Eike Rathke
erack at redhat.com
Wed Aug 28 08:58:39 PDT 2013
i18nlangtag/qa/cppunit/test_languagetag.cxx | 56 ++++++++++++-----
i18nlangtag/source/languagetag/languagetag.cxx | 81 ++++++++++++++++++++++++-
include/i18nlangtag/languagetag.hxx | 11 +++
3 files changed, 131 insertions(+), 17 deletions(-)
New commits:
commit b5f91618d710803a26fa23d154d7252384f74e6f
Author: Eike Rathke <erack at redhat.com>
Date: Wed Aug 28 17:57:27 2013 +0200
added unit test for ca-valencia
Change-Id: I2a36296e1210e349a7b53d999a2438aa45f3e2c2
diff --git a/i18nlangtag/qa/cppunit/test_languagetag.cxx b/i18nlangtag/qa/cppunit/test_languagetag.cxx
index 2e82fcc..49c6c5f 100644
--- a/i18nlangtag/qa/cppunit/test_languagetag.cxx
+++ b/i18nlangtag/qa/cppunit/test_languagetag.cxx
@@ -174,6 +174,28 @@ void TestLanguageTag::testAllTags()
}
{
+ OUString s_ca_valencia( "ca-valencia" );
+ LanguageTag ca_valencia( s_ca_valencia, true );
+ lang::Locale aLocale = ca_valencia.getLocale();
+ CPPUNIT_ASSERT( ca_valencia.getBcp47() == s_ca_valencia );
+ CPPUNIT_ASSERT( aLocale.Language == "qlt" );
+ CPPUNIT_ASSERT( aLocale.Country == "" );
+ CPPUNIT_ASSERT( aLocale.Variant == s_ca_valencia );
+ CPPUNIT_ASSERT( ca_valencia.getLanguageType() == LANGUAGE_SYSTEM );
+ CPPUNIT_ASSERT( ca_valencia.isValidBcp47() == true );
+ CPPUNIT_ASSERT( ca_valencia.isIsoLocale() == false );
+ CPPUNIT_ASSERT( ca_valencia.isIsoODF() == false );
+ CPPUNIT_ASSERT( ca_valencia.getLanguage() == "ca" );
+ CPPUNIT_ASSERT( ca_valencia.getCountry() == "" );
+ CPPUNIT_ASSERT( ca_valencia.getScript() == "" );
+ CPPUNIT_ASSERT( ca_valencia.getLanguageAndScript() == "ca" );
+ ::std::vector< OUString > ca_ES_valencia_Fallbacks( ca_valencia.getFallbackStrings());
+ CPPUNIT_ASSERT( ca_ES_valencia_Fallbacks.size() == 2);
+ CPPUNIT_ASSERT( ca_ES_valencia_Fallbacks[0] == "ca-valencia");
+ CPPUNIT_ASSERT( ca_ES_valencia_Fallbacks[1] == "ca");
+ }
+
+ {
OUString s_de_DE( "de-DE" );
LanguageTag de_DE( s_de_DE, true );
lang::Locale aLocale = de_DE.getLocale();
commit c179594dafa156efdcef6051eff23e9f1b717d1b
Author: Eike Rathke <erack at redhat.com>
Date: Wed Aug 28 17:55:39 2013 +0200
need to check for variants in isIsoODF()
Change-Id: I88be91690f11bc11d70bd54310d0130723245286
diff --git a/i18nlangtag/source/languagetag/languagetag.cxx b/i18nlangtag/source/languagetag/languagetag.cxx
index e4341d8..6c0581a 100644
--- a/i18nlangtag/source/languagetag/languagetag.cxx
+++ b/i18nlangtag/source/languagetag/languagetag.cxx
@@ -1123,10 +1123,11 @@ bool LanguageTag::isIsoODF() const
if (isIsoLocale())
return ((meIsIsoODF = DECISION_YES) == DECISION_YES);
// If this is not ISO locale for which script must not exist it can
- // still be ISO locale plus ISO script lll-Ssss-CC
+ // still be ISO locale plus ISO script lll-Ssss-CC, but not ll-vvvv ...
+ // ll-vvvvvvvv
meIsIsoODF = ((maBcp47.getLength() <= 11 &&
- isIsoLanguage( getLanguage()) && isIsoCountry( getRegion()) && isIsoScript( getScript())) ?
- DECISION_YES : DECISION_NO);
+ isIsoLanguage( getLanguage()) && isIsoCountry( getRegion()) && isIsoScript( getScript()) &&
+ getVariants().isEmpty()) ? DECISION_YES : DECISION_NO);
}
return meIsIsoODF == DECISION_YES;
}
commit 4a6ac8965b95b4775b438398a3e17d1b226bcea7
Author: Eike Rathke <erack at redhat.com>
Date: Wed Aug 28 17:41:14 2013 +0200
added unit test for fallback strings
Change-Id: Ife3694e9432141e638d8f6050f4e5335c254cdbf
diff --git a/i18nlangtag/qa/cppunit/test_languagetag.cxx b/i18nlangtag/qa/cppunit/test_languagetag.cxx
index 41c1cc9..2e82fcc 100644
--- a/i18nlangtag/qa/cppunit/test_languagetag.cxx
+++ b/i18nlangtag/qa/cppunit/test_languagetag.cxx
@@ -165,6 +165,12 @@ void TestLanguageTag::testAllTags()
CPPUNIT_ASSERT( ca_ES_valencia.getCountry() == "ES" );
CPPUNIT_ASSERT( ca_ES_valencia.getScript() == "" );
CPPUNIT_ASSERT( ca_ES_valencia.getLanguageAndScript() == "ca" );
+ ::std::vector< OUString > ca_ES_valencia_Fallbacks( ca_ES_valencia.getFallbackStrings());
+ CPPUNIT_ASSERT( ca_ES_valencia_Fallbacks.size() == 4);
+ CPPUNIT_ASSERT( ca_ES_valencia_Fallbacks[0] == "ca-ES-valencia");
+ CPPUNIT_ASSERT( ca_ES_valencia_Fallbacks[1] == "ca-valencia");
+ CPPUNIT_ASSERT( ca_ES_valencia_Fallbacks[2] == "ca-ES");
+ CPPUNIT_ASSERT( ca_ES_valencia_Fallbacks[3] == "ca");
}
{
commit a95a980e1e338b238f70f010057b017e08b47d79
Author: Eike Rathke <erack at redhat.com>
Date: Wed Aug 28 17:25:33 2013 +0200
reorder fall back strings for language with variant
Change-Id: I0e67eec9efa32c1d3d3f8d3ad3845368822bb0ee
diff --git a/i18nlangtag/source/languagetag/languagetag.cxx b/i18nlangtag/source/languagetag/languagetag.cxx
index baec229..e4341d8 100644
--- a/i18nlangtag/source/languagetag/languagetag.cxx
+++ b/i18nlangtag/source/languagetag/languagetag.cxx
@@ -1184,6 +1184,7 @@ LanguageTag & LanguageTag::makeFallback()
if (hasScript())
{
OUString aScript( getScript());
+ bool bHaveLanguageScriptVariant = false;
if (!aCountry.isEmpty())
{
if (!aVariants.isEmpty())
@@ -1191,12 +1192,18 @@ LanguageTag & LanguageTag::makeFallback()
aTmp = aLanguage + "-" + aScript + "-" + aCountry + "-" + aVariants;
if (aTmp != aVec[0])
aVec.push_back( aTmp);
+ // Language with variant but without country before language
+ // without variant but with country.
+ aTmp = aLanguage + "-" + aScript + "-" + aVariants;
+ if (aTmp != aVec[0])
+ aVec.push_back( aTmp);
+ bHaveLanguageScriptVariant = true;
}
aTmp = aLanguage + "-" + aScript + "-" + aCountry;
if (aTmp != aVec[0])
aVec.push_back( aTmp);
}
- if (!aVariants.isEmpty())
+ if (!aVariants.isEmpty() && !bHaveLanguageScriptVariant)
{
aTmp = aLanguage + "-" + aScript + "-" + aVariants;
if (aTmp != aVec[0])
@@ -1206,6 +1213,7 @@ LanguageTag & LanguageTag::makeFallback()
if (aTmp != aVec[0])
aVec.push_back( aTmp);
}
+ bool bHaveLanguageVariant = false;
if (!aCountry.isEmpty())
{
if (!aVariants.isEmpty())
@@ -1213,12 +1221,18 @@ LanguageTag & LanguageTag::makeFallback()
aTmp = aLanguage + "-" + aCountry + "-" + aVariants;
if (aTmp != aVec[0])
aVec.push_back( aTmp);
+ // Language with variant but without country before language
+ // without variant but with country.
+ aTmp = aLanguage + "-" + aVariants;
+ if (aTmp != aVec[0])
+ aVec.push_back( aTmp);
+ bHaveLanguageVariant = true;
}
aTmp = aLanguage + "-" + aCountry;
if (aTmp != aVec[0])
aVec.push_back( aTmp);
}
- if (!aVariants.isEmpty())
+ if (!aVariants.isEmpty() && !bHaveLanguageVariant)
{
aTmp = aLanguage + "-" + aVariants;
if (aTmp != aVec[0])
commit 450e9e3e5efca351d593792580d6b81a2e5fde9c
Author: Eike Rathke <erack at redhat.com>
Date: Wed Aug 28 17:11:51 2013 +0200
grml.. lt_list_value is an lt_variant_t*
Change-Id: I74b4085394955906e075d77bc761dbdc92d06182
diff --git a/i18nlangtag/source/languagetag/languagetag.cxx b/i18nlangtag/source/languagetag/languagetag.cxx
index 57a87ec..baec229 100644
--- a/i18nlangtag/source/languagetag/languagetag.cxx
+++ b/i18nlangtag/source/languagetag/languagetag.cxx
@@ -853,13 +853,17 @@ OUString LanguageTag::getVariantsFromLangtag()
const lt_list_t* pVariantsT = lt_tag_get_variants( MPLANGTAG);
for (const lt_list_t* pE = pVariantsT; pE; pE = lt_list_next( pE))
{
- const lt_pointer_t pV = lt_list_value( pE);
- if (pV)
+ const lt_variant_t* pVariantT = static_cast<const lt_variant_t*>(lt_list_value( pE));
+ if (pVariantT)
{
- if (aVariants.isEmpty())
- aVariants = OUString::createFromAscii( static_cast<const char*>(pV));
- else
- aVariants += "-" + OUString::createFromAscii( static_cast<const char*>(pV));
+ const char* p = lt_variant_get_tag( pVariantT);
+ if (p)
+ {
+ if (aVariants.isEmpty())
+ aVariants = OUString::createFromAscii( p);
+ else
+ aVariants += "-" + OUString::createFromAscii( p);
+ }
}
}
}
commit 6ba5abe2fe52f7fe2ccc775ee562a230dd871373
Author: Eike Rathke <erack at redhat.com>
Date: Wed Aug 28 16:27:09 2013 +0200
match names with tag
Change-Id: I817b2cf9a015709d90b3f1c22290bce0cbc31eab
diff --git a/i18nlangtag/qa/cppunit/test_languagetag.cxx b/i18nlangtag/qa/cppunit/test_languagetag.cxx
index 08292b1..41c1cc9 100644
--- a/i18nlangtag/qa/cppunit/test_languagetag.cxx
+++ b/i18nlangtag/qa/cppunit/test_languagetag.cxx
@@ -145,26 +145,26 @@ void TestLanguageTag::testAllTags()
}
{
- OUString s_ca_valencia_ES( "ca-ES-valencia" );
- LanguageTag ca_valencia_ES( s_ca_valencia_ES, true );
- lang::Locale aLocale = ca_valencia_ES.getLocale();
- CPPUNIT_ASSERT( ca_valencia_ES.getBcp47() == s_ca_valencia_ES );
+ OUString s_ca_ES_valencia( "ca-ES-valencia" );
+ LanguageTag ca_ES_valencia( s_ca_ES_valencia, true );
+ lang::Locale aLocale = ca_ES_valencia.getLocale();
+ CPPUNIT_ASSERT( ca_ES_valencia.getBcp47() == s_ca_ES_valencia );
CPPUNIT_ASSERT( aLocale.Language == "qlt" );
CPPUNIT_ASSERT( aLocale.Country == "ES" );
- CPPUNIT_ASSERT( aLocale.Variant == s_ca_valencia_ES );
+ CPPUNIT_ASSERT( aLocale.Variant == s_ca_ES_valencia );
/* TODO: conversion doesn't know this yet, once it does activate test. */
#if 0
- CPPUNIT_ASSERT( ca_valencia_ES.getLanguageType() == LANGUAGE_USER_CATALAN_VALENCIAN );
+ CPPUNIT_ASSERT( ca_ES_valencia.getLanguageType() == LANGUAGE_USER_CATALAN_VALENCIAN );
#else
- CPPUNIT_ASSERT( ca_valencia_ES.getLanguageType() == LANGUAGE_SYSTEM );
+ CPPUNIT_ASSERT( ca_ES_valencia.getLanguageType() == LANGUAGE_SYSTEM );
#endif
- CPPUNIT_ASSERT( ca_valencia_ES.isValidBcp47() == true );
- CPPUNIT_ASSERT( ca_valencia_ES.isIsoLocale() == false );
- CPPUNIT_ASSERT( ca_valencia_ES.isIsoODF() == false );
- CPPUNIT_ASSERT( ca_valencia_ES.getLanguage() == "ca" );
- CPPUNIT_ASSERT( ca_valencia_ES.getCountry() == "ES" );
- CPPUNIT_ASSERT( ca_valencia_ES.getScript() == "" );
- CPPUNIT_ASSERT( ca_valencia_ES.getLanguageAndScript() == "ca" );
+ CPPUNIT_ASSERT( ca_ES_valencia.isValidBcp47() == true );
+ CPPUNIT_ASSERT( ca_ES_valencia.isIsoLocale() == false );
+ CPPUNIT_ASSERT( ca_ES_valencia.isIsoODF() == false );
+ CPPUNIT_ASSERT( ca_ES_valencia.getLanguage() == "ca" );
+ CPPUNIT_ASSERT( ca_ES_valencia.getCountry() == "ES" );
+ CPPUNIT_ASSERT( ca_ES_valencia.getScript() == "" );
+ CPPUNIT_ASSERT( ca_ES_valencia.getLanguageAndScript() == "ca" );
}
{
commit adb56fbc7326b99f556683ea1bc73b70ca9ebefd
Author: Eike Rathke <erack at redhat.com>
Date: Wed Aug 28 16:21:37 2013 +0200
include variants in fallback strings
Change-Id: I73024a91740dbfde6df78c5388ae4861a6e44294
diff --git a/i18nlangtag/source/languagetag/languagetag.cxx b/i18nlangtag/source/languagetag/languagetag.cxx
index 8ea944b..57a87ec 100644
--- a/i18nlangtag/source/languagetag/languagetag.cxx
+++ b/i18nlangtag/source/languagetag/languagetag.cxx
@@ -1175,26 +1175,51 @@ LanguageTag & LanguageTag::makeFallback()
return aVec;
}
aVec.push_back( getBcp47());
+ OUString aVariants( getVariants());
OUString aTmp;
if (hasScript())
{
OUString aScript( getScript());
if (!aCountry.isEmpty())
{
+ if (!aVariants.isEmpty())
+ {
+ aTmp = aLanguage + "-" + aScript + "-" + aCountry + "-" + aVariants;
+ if (aTmp != aVec[0])
+ aVec.push_back( aTmp);
+ }
aTmp = aLanguage + "-" + aScript + "-" + aCountry;
if (aTmp != aVec[0])
aVec.push_back( aTmp);
}
+ if (!aVariants.isEmpty())
+ {
+ aTmp = aLanguage + "-" + aScript + "-" + aVariants;
+ if (aTmp != aVec[0])
+ aVec.push_back( aTmp);
+ }
aTmp = aLanguage + "-" + aScript;
if (aTmp != aVec[0])
aVec.push_back( aTmp);
}
if (!aCountry.isEmpty())
{
+ if (!aVariants.isEmpty())
+ {
+ aTmp = aLanguage + "-" + aCountry + "-" + aVariants;
+ if (aTmp != aVec[0])
+ aVec.push_back( aTmp);
+ }
aTmp = aLanguage + "-" + aCountry;
if (aTmp != aVec[0])
aVec.push_back( aTmp);
}
+ if (!aVariants.isEmpty())
+ {
+ aTmp = aLanguage + "-" + aVariants;
+ if (aTmp != aVec[0])
+ aVec.push_back( aTmp);
+ }
aTmp = aLanguage;
if (aTmp != aVec[0])
aVec.push_back( aTmp);
commit 4875278bfb0e4463e35063afc20282fc837731df
Author: Eike Rathke <erack at redhat.com>
Date: Wed Aug 28 16:10:18 2013 +0200
added getVariants()
Change-Id: Ib5a880698dd6faea9a5b592221f2b302889bfc24
diff --git a/i18nlangtag/source/languagetag/languagetag.cxx b/i18nlangtag/source/languagetag/languagetag.cxx
index c2716e4..8ea944b 100644
--- a/i18nlangtag/source/languagetag/languagetag.cxx
+++ b/i18nlangtag/source/languagetag/languagetag.cxx
@@ -842,6 +842,31 @@ OUString LanguageTag::getRegionFromLangtag()
}
+OUString LanguageTag::getVariantsFromLangtag()
+{
+ OUString aVariants;
+ synCanonicalize();
+ if (maBcp47.isEmpty())
+ return aVariants;
+ if (mpImplLangtag)
+ {
+ const lt_list_t* pVariantsT = lt_tag_get_variants( MPLANGTAG);
+ for (const lt_list_t* pE = pVariantsT; pE; pE = lt_list_next( pE))
+ {
+ const lt_pointer_t pV = lt_list_value( pE);
+ if (pV)
+ {
+ if (aVariants.isEmpty())
+ aVariants = OUString::createFromAscii( static_cast<const char*>(pV));
+ else
+ aVariants += "-" + OUString::createFromAscii( static_cast<const char*>(pV));
+ }
+ }
+ }
+ return aVariants;
+}
+
+
const com::sun::star::lang::Locale & LanguageTag::getLocale( bool bResolveSystem ) const
{
if (!bResolveSystem && mbSystemLocale)
@@ -1016,6 +1041,12 @@ OUString LanguageTag::getRegion() const
}
+OUString LanguageTag::getVariants() const
+{
+ return const_cast<LanguageTag*>(this)->getVariantsFromLangtag();
+}
+
+
OUString LanguageTag::getGlibcLocaleString( const OUString & rEncoding ) const
{
OUString aRet;
diff --git a/include/i18nlangtag/languagetag.hxx b/include/i18nlangtag/languagetag.hxx
index 1a1d69d..3843493 100644
--- a/include/i18nlangtag/languagetag.hxx
+++ b/include/i18nlangtag/languagetag.hxx
@@ -184,6 +184,16 @@ public:
*/
OUString getRegion() const;
+ /** Get BCP 47 variant subtags, of the IANA Language Subtag Registry.
+
+ If there are multiple variant subtags they are separated by '-'.
+
+ This is NOT related to Locale.Variant!
+
+ Always resolves an empty tag to the system locale.
+ */
+ OUString getVariants() const;
+
/** Get a GLIBC locale string.
Always resolves an empty tag to the system locale.
@@ -483,6 +493,7 @@ private:
OUString getLanguageFromLangtag();
OUString getScriptFromLangtag();
OUString getRegionFromLangtag();
+ OUString getVariantsFromLangtag();
void resetVars();
More information about the Libreoffice-commits
mailing list