Resolves: tdf#154582 Obtain English DisplayName before CompatibilityName

... for Add-Ins from configuration.

Change-Id: If13d692ca7550e69d2f6e3ff72747d17aee3e7f7
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/149995
Reviewed-by: Eike Rathke <erack@redhat.com>
Tested-by: Jenkins
(cherry picked from commit dcb50fe7444dd746ba4d3f8476026bb997a595b5)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/149976
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
diff --git a/sc/source/core/tool/addincol.cxx b/sc/source/core/tool/addincol.cxx
index 99f8061..9ddc97f 100644
--- a/sc/source/core/tool/addincol.cxx
+++ b/sc/source/core/tool/addincol.cxx
@@ -360,7 +360,8 @@ void ScUnoAddInCollection::ReadConfiguration()

    ScAddInCfg& rAddInConfig = SC_MOD()->GetAddInCfg();

    // additional, temporary config item for the compatibility names
    // Additional, temporary config item for the display names and
    // compatibility names.
    ScLinkConfigItem aAllLocalesConfig( CFGPATH_ADDINS, ConfigItemMode::AllLocales );
    // CommitLink is not used (only reading values)

@@ -441,6 +442,35 @@ void ScUnoAddInCollection::ReadConfiguration()
                    nCategory = lcl_GetCategory( aCategoryName );
                }

                // get English display name

                OUString aDisplayNamePath(aFuncPropPath + CFGSTR_DISPLAYNAME);
                uno::Sequence<OUString> aDisplayNamePropNames( &aDisplayNamePath, 1 );

                uno::Sequence<uno::Any> aDisplayNameProperties = aAllLocalesConfig.GetProperties( aDisplayNamePropNames );
                if ( aDisplayNameProperties.getLength() == 1 )
                {
                    uno::Sequence<beans::PropertyValue> aLocalEntries;
                    if ( aDisplayNameProperties[0] >>= aLocalEntries )
                    {
                        for ( const beans::PropertyValue& rConfig : std::as_const(aLocalEntries) )
                        {
                            // PropertyValue name is the locale ("convert" from
                            // string to canonicalize).
                            OUString aLocale( LanguageTag( rConfig.Name, true).getBcp47( false));
                            // PropertyValue value is the localized value (string in this case).
                            OUString aName;
                            rConfig.Value >>= aName;
                            // Accept 'en' and 'en-...' but prefer 'en-US'.
                            if (aLocale == "en-US" && !aName.isEmpty())
                                aEnglishName = aName;
                            else if (aEnglishName.isEmpty() && (aLocale == "en" || aLocale.startsWith("en-")))
                                aEnglishName = aName;
                        }
                    }
                }
                bool bNeedEnglish = aEnglishName.isEmpty();

                // get compatibility names

                ::std::vector<ScUnoAddInFuncData::LocalizedName> aCompNames;
@@ -457,17 +487,23 @@ void ScUnoAddInCollection::ReadConfiguration()
                        for ( const beans::PropertyValue& rConfig : std::as_const(aLocalEntries) )
                        {
                            // PropertyValue name is the locale ("convert" from
                            // string to canonicalize)
                            // string to canonicalize).
                            OUString aLocale( LanguageTag( rConfig.Name, true).getBcp47( false));
                            // PropertyValue value is the localized value (string in this case)
                            // PropertyValue value is the localized value (string in this case).
                            OUString aName;
                            rConfig.Value >>= aName;
                            aCompNames.emplace_back( aLocale, aName);
                            // Accept 'en' and 'en-...' but prefer 'en-US'.
                            if (aLocale == "en-US")
                                aEnglishName = aName;
                            else if (aEnglishName.isEmpty() && (aLocale == "en" || aLocale.startsWith("en-")))
                                aEnglishName = aName;
                            if (!aName.isEmpty())
                            {
                                aCompNames.emplace_back( aLocale, aName);
                                if (bNeedEnglish)
                                {
                                    // Accept 'en' and 'en-...' but prefer 'en-US'.
                                    if (aLocale == "en-US")
                                        aEnglishName = aName;
                                    else if (aEnglishName.isEmpty() && (aLocale == "en" || aLocale.startsWith("en-")))
                                        aEnglishName = aName;
                                }
                            }
                        }
                    }
                }