[Libreoffice-commits] core.git: i18nlangtag/qa i18nlangtag/source

Eike Rathke erack at redhat.com
Thu Sep 19 04:39:00 PDT 2013


 i18nlangtag/qa/cppunit/test_languagetag.cxx    |   14 +++++++++++-
 i18nlangtag/source/languagetag/languagetag.cxx |   29 ++++++++++++++++++-------
 2 files changed, 34 insertions(+), 9 deletions(-)

New commits:
commit f86404450621bbee6feaaee0f43f5e53d9501796
Author: Eike Rathke <erack at redhat.com>
Date:   Thu Sep 19 13:37:56 2013 +0200

    'de-1901' is a valid fallback, 'en-oed' is not
    
    Change-Id: I73b821eaff82796080ce123e37466ec53c327141

diff --git a/i18nlangtag/qa/cppunit/test_languagetag.cxx b/i18nlangtag/qa/cppunit/test_languagetag.cxx
index 079973e..2368ca2 100644
--- a/i18nlangtag/qa/cppunit/test_languagetag.cxx
+++ b/i18nlangtag/qa/cppunit/test_languagetag.cxx
@@ -319,7 +319,7 @@ void TestLanguageTag::testAllTags()
     }
 
     // 'de-1901' derived from 'de-DE-1901' grandfathered to check that it is
-    // accepted as (DIGIT 3*ALNUM) variant
+    // accepted as (DIGIT 3ALNUM) variant
     {
         OUString s_de_1901( "de-1901" );
         LanguageTag de_1901( s_de_1901 );
@@ -334,6 +334,10 @@ void TestLanguageTag::testAllTags()
         CPPUNIT_ASSERT( de_1901.isIsoODF() == false );
         CPPUNIT_ASSERT( de_1901.getLanguageAndScript() == "de" );
         CPPUNIT_ASSERT( de_1901.getVariants() == "1901" );
+        ::std::vector< OUString > de_1901_Fallbacks( de_1901.getFallbackStrings( true));
+        CPPUNIT_ASSERT( de_1901_Fallbacks.size() == 2);
+        CPPUNIT_ASSERT( de_1901_Fallbacks[0] == "de-1901");
+        CPPUNIT_ASSERT( de_1901_Fallbacks[1] == "de");
     }
 
     // 'en-GB-oed' is known grandfathered for English, Oxford English
@@ -350,6 +354,14 @@ void TestLanguageTag::testAllTags()
         CPPUNIT_ASSERT( en_GB_oed.isValidBcp47() == true );
         CPPUNIT_ASSERT( en_GB_oed.isIsoLocale() == false );
         CPPUNIT_ASSERT( en_GB_oed.isIsoODF() == false );
+        CPPUNIT_ASSERT( en_GB_oed.getLanguageAndScript() == "en" );
+        CPPUNIT_ASSERT( en_GB_oed.getVariants() == "oed" );
+        ::std::vector< OUString > en_GB_oed_Fallbacks( en_GB_oed.getFallbackStrings( true));
+        CPPUNIT_ASSERT( en_GB_oed_Fallbacks.size() == 3);
+        CPPUNIT_ASSERT( en_GB_oed_Fallbacks[0] == "en-GB-oed");
+        CPPUNIT_ASSERT( en_GB_oed_Fallbacks[1] == "en-GB");
+        CPPUNIT_ASSERT( en_GB_oed_Fallbacks[2] == "en");
+        // 'en-oed' is not a valid fallback!
     }
 
     // 'qtz' is a local use known pseudolocale for key ID resource
diff --git a/i18nlangtag/source/languagetag/languagetag.cxx b/i18nlangtag/source/languagetag/languagetag.cxx
index 3aad527..8399865 100644
--- a/i18nlangtag/source/languagetag/languagetag.cxx
+++ b/i18nlangtag/source/languagetag/languagetag.cxx
@@ -1682,10 +1682,17 @@ LanguageTag & LanguageTag::makeFallback()
                 aVec.push_back( aTmp);
             // Language with variant but without country before language
             // without variant but with country.
-            aTmp = aLanguage + "-" + aVariants;
-            if (aTmp != maBcp47)
-                aVec.push_back( aTmp);
-            bHaveLanguageVariant = true;
+            // But only if variant is not from a grandfathered tag that
+            // wouldn't match the rules, i.e. "de-1901" is fine but "en-oed" is
+            // not.
+            if (aVariants.getLength() >= 5 ||
+                    (aVariants.getLength() == 4 && '0' <= aVariants[0] && aVariants[0] <= '9'))
+            {
+                aTmp = aLanguage + "-" + aVariants;
+                if (aTmp != maBcp47)
+                    aVec.push_back( aTmp);
+                bHaveLanguageVariant = true;
+            }
         }
         aTmp = aLanguage + "-" + aCountry;
         if (aTmp != maBcp47)
@@ -1693,9 +1700,15 @@ LanguageTag & LanguageTag::makeFallback()
     }
     if (!aVariants.isEmpty() && !bHaveLanguageVariant)
     {
-        aTmp = aLanguage + "-" + aVariants;
-        if (aTmp != maBcp47)
-            aVec.push_back( aTmp);
+        // Only if variant is not from a grandfathered tag that wouldn't match
+        // the rules, i.e. "de-1901" is fine but "en-oed" is not.
+        if (aVariants.getLength() >= 5 ||
+                (aVariants.getLength() == 4 && '0' <= aVariants[0] && aVariants[0] <= '9'))
+        {
+            aTmp = aLanguage + "-" + aVariants;
+            if (aTmp != maBcp47)
+                aVec.push_back( aTmp);
+        }
     }
 
     // Insert legacy fallbacks with country before language-only, but only
@@ -1797,7 +1810,7 @@ LanguageTagImpl::Extraction LanguageTagImpl::simpleExtract( const OUString& rBcp
             sal_Unicode c = rBcp47[nHyph1+1];
             if ('0' <= c && c <= '9')
             {
-                // (DIGIT 3*ALNUM) vvvv variant instead of Ssss script
+                // (DIGIT 3ALNUM) vvvv variant instead of Ssss script
                 rLanguage = rBcp47.copy( 0, nHyph1).toAsciiLowerCase();
                 rScript   = rCountry = OUString();
                 rVariants = rBcp47.copy( nHyph1 + 1);


More information about the Libreoffice-commits mailing list