i18nlangtag/source/isolang/isolang.cxx  |   60 +++++++++++---------------------
 i18nlangtag/source/isolang/mslangid.cxx |    3 +
 svl/source/numbers/numfmuno.cxx         |    2 -
 3 files changed, 25 insertions(+), 40 deletions(-)

New commits:
commit bba6a4ed92a0feb288a9dedd648d623bee02a3ce
Author:     Eike Rathke <er...@redhat.com>
AuthorDate: Sun Oct 24 23:10:30 2021 +0200
Commit:     Eike Rathke <er...@redhat.com>
CommitDate: Mon Oct 25 11:18:31 2021 +0200

    Get rid of fuzziness in MsLangId::Conversion::convertIsoNamesToLanguage()
    
    With on-the-fly LanguageTag the fuzzy fallbacks for a few
    languages aren't needed anymore. Proper fallbacks should be
    obtained when needed, like when configuring default locales, or
    configured values used after.
    
    Change-Id: I8b85b8099e085508435036ac846db6c3e516dc23
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/124127
    Reviewed-by: Eike Rathke <er...@redhat.com>
    Tested-by: Jenkins

diff --git a/i18nlangtag/source/isolang/isolang.cxx 
b/i18nlangtag/source/isolang/isolang.cxx
index 87051fb999bb..03f92c2decff 100644
--- a/i18nlangtag/source/isolang/isolang.cxx
+++ b/i18nlangtag/source/isolang/isolang.cxx
@@ -17,6 +17,7 @@
  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
  */
 
+#include <sal/log.hxx>
 #include <rtl/ustring.hxx>
 #include <rtl/string.hxx>
 
@@ -138,42 +139,19 @@ struct IsoLangOtherEntry
 // The default entry for a LangID <-> ISO mapping has to be first. For
 // conversion of legacy mappings one LangID can map to multiple ISO codes
 // except if the LangID is primary-only, and one ISO code combination can map
-// to multiple LangIDs. For compatibility with already existing calls it can
-// also be a sequence as follows:
+// to multiple LangIDs.
 
-// LANGUAGE_ENGLISH,    "en", ""
-// LANGUAGE_ENGLISH_US, "en", "US"
-
-// Here, in a convertIsoNamesToLanguage() call "en-US" is converted to
-// LANGUAGE_ENGLISH_US and "en" is converted to LANGUAGE_ENGLISH. A call with
-// "en-ZZ" (not in table) would result in LANGUAGE_ENGLISH because the first
-// entry matching the language and not having a country is returned, regardless
-// of whether being sorted before or after other entries of the same language
-// with some country. To obtain a _locale_ (not language only) in the order
-// given, lookupFallbackLocale() must be called.
-
-// If the sequence instead was
-
-// LANGUAGE_ENGLISH_US, "en", "US"
-// LANGUAGE_ENGLISH,    "en", ""
-
-// in a convertIsoNamesToLanguage() call "en-US" would still be converted to
-// LANGUAGE_ENGLISH_US, but "en" would _also_ be converted to
-// LANGUAGE_ENGLISH_US because no country was passed and it is the first entry
-// to match the language, see code. A call with "en-ZZ" (not in table) would
-// still result in LANGUAGE_ENGLISH.
-
-/* Currently (2013-08-29) only these primary LangID are still used literally in
- * code:
+/* Currently (2013-08-29 and 2021-10-24) only these primary LangID are still
+ * used literally in code:
  * LANGUAGE_ENGLISH  LANGUAGE_ARABIC_PRIMARY_ONLY
  */
 
 IsoLanguageCountryEntry const aImplIsoLangEntries[] =
 {
     // MS-LANGID codes,             ISO639-1/2/3, ISO3166, override
-    { LANGUAGE_ENGLISH,                     "en", ""  , k0    },
     { LANGUAGE_ENGLISH_US,                  "en", "US", k0    },
     { LANGUAGE_ENGLISH_UK,                  "en", "GB", k0    },
+    { LANGUAGE_ENGLISH,                     "en", ""  , k0    },
     { LANGUAGE_ENGLISH_AUS,                 "en", "AU", k0    },
     { LANGUAGE_ENGLISH_CAN,                 "en", "CA", k0    },
     { LANGUAGE_FRENCH,                      "fr", "FR", k0    },
@@ -377,7 +355,6 @@ IsoLanguageCountryEntry const aImplIsoLangEntries[] =
     { LANGUAGE_FRENCH_ZAIRE,                "fr", "CD", k0    },    // 
Democratic Republic Of Congo
     { LANGUAGE_FRENCH_MOROCCO,              "fr", "MA", k0    },
     { LANGUAGE_FRENCH_REUNION,              "fr", "RE", k0    },
-    { LANGUAGE_FRENCH,                      "fr", ""  , k0    },    // needed 
as a catcher before other "fr" entries!
     { LANGUAGE_FRISIAN_NETHERLANDS,         "fy", "NL", k0    },
     { LANGUAGE_GAELIC_IRELAND,              "ga", "IE", k0    },
     { LANGUAGE_GAELIC_SCOTLAND,             "gd", "GB", k0    },
@@ -1336,8 +1313,6 @@ LanguageType 
MsLangId::Conversion::convertIsoNamesToLanguage( const OUString& rL
     // country is upper case in table
     OUString aUpperCountry = rCountry.toAsciiUpperCase();
 
-    const IsoLanguageCountryEntry* pFirstLang = nullptr;
-
     if (!bSkipIsoTable)
     {
         //  first look for exact match
@@ -1349,10 +1324,6 @@ LanguageType 
MsLangId::Conversion::convertIsoNamesToLanguage( const OUString& rL
                 if ( aUpperCountry.isEmpty() ||
                         aUpperCountry.equalsAscii( pEntry->maCountry ) )
                     return pEntry->mnLang;
-                if ( !pFirstLang )
-                    pFirstLang = pEntry;
-                else if ( !*pEntry->maCountry )
-                    pFirstLang = pEntry;
             }
         }
 
@@ -1392,10 +1363,6 @@ LanguageType 
MsLangId::Conversion::convertIsoNamesToLanguage( const OUString& rL
 
     if (!bSkipIsoTable)
     {
-        // If the language is correct, then we return the default language
-        if ( pFirstLang )
-            return pFirstLang->mnLang;
-
         //  if only the country is set, look for any entry matching the country
         //  (to allow reading country and language in separate steps, in any 
order)
         if ( !rCountry.isEmpty() && rLang.isEmpty() )
@@ -1434,7 +1401,22 @@ LanguageType 
MsLangId::Conversion::convertIsoNamesToLanguage( std::string_view r
 {
     OUString aLang = OStringToOUString( rLang, RTL_TEXTENCODING_ASCII_US);
     OUString aCountry = OStringToOUString( rCountry, 
RTL_TEXTENCODING_ASCII_US);
-    return convertIsoNamesToLanguage( aLang, aCountry, false);
+    LanguageType nLang = convertIsoNamesToLanguage( aLang, aCountry, false);
+
+    // XXX: called *only* by static convertUnxByteStringToLanguage() so we can
+    // actually call into LanguageTag to create an on-the-fly mapping.
+    if (nLang == LANGUAGE_DONTKNOW)
+    {
+        nLang = LanguageTag( aLang + "-" + aCountry).getLanguageType(false);
+        SAL_WARN("i18nlangtag", "convertIsoNamesToLanguage(string_view): 
on-the-fly for {"
+                << aLang << "-" << aCountry << "} " << nLang);
+        if (nLang == LANGUAGE_DONTKNOW)
+        {
+            SAL_WARN("i18nlangtag", "convertIsoNamesToLanguage(string_view): 
on-the-fly bad, using {en-US}");
+            nLang = LANGUAGE_ENGLISH_US;
+        }
+    }
+    return nLang;
 }
 
 namespace {
diff --git a/i18nlangtag/source/isolang/mslangid.cxx 
b/i18nlangtag/source/isolang/mslangid.cxx
index 4cc448768f3a..758a6e7aef3f 100644
--- a/i18nlangtag/source/isolang/mslangid.cxx
+++ b/i18nlangtag/source/isolang/mslangid.cxx
@@ -18,6 +18,7 @@
  */
 
 #include <sal/config.h>
+#include <sal/log.hxx>
 #include <rtl/ustring.hxx>
 #include <com/sun/star/i18n/ScriptType.hpp>
 
@@ -101,6 +102,7 @@ LanguageType MsLangId::getConfiguredSystemLanguage()
 {
     if (nConfiguredSystemLanguage != LANGUAGE_SYSTEM)
         return nConfiguredSystemLanguage;
+    SAL_WARN("i18nlangtag", "MsLangId::getConfiguredSystemLanguage() - not 
configured yet");
     return getSystemLanguage();
 }
 
@@ -110,6 +112,7 @@ LanguageType MsLangId::getConfiguredSystemUILanguage()
 {
     if (nConfiguredSystemUILanguage != LANGUAGE_SYSTEM)
         return nConfiguredSystemUILanguage;
+    SAL_WARN("i18nlangtag", "MsLangId::getConfiguredSystemUILanguage() - not 
configured yet");
     return getSystemUILanguage();
 }
 
diff --git a/svl/source/numbers/numfmuno.cxx b/svl/source/numbers/numfmuno.cxx
index 679dbe16f7fc..416de9297179 100644
--- a/svl/source/numbers/numfmuno.cxx
+++ b/svl/source/numbers/numfmuno.cxx
@@ -97,7 +97,7 @@ static const SfxItemPropertyMapEntry* 
lcl_GetNumberSettingsPropertyMap()
 
 static LanguageType lcl_GetLanguage( const lang::Locale& rLocale )
 {
-    LanguageType eRet = LanguageTag::convertToLanguageType( rLocale, false);
+    LanguageType eRet = LanguageTag( 
rLocale).makeFallback().getLanguageType(false);
     if ( eRet == LANGUAGE_NONE )
         eRet = LANGUAGE_SYSTEM; //! or throw an exception?
 

Reply via email to