[Libreoffice-commits] core.git: xmlhelp/source

Eike Rathke (via logerrit) logerrit at kemper.freedesktop.org
Fri Jun 28 18:50:19 UTC 2019


 xmlhelp/source/cxxhelp/provider/databases.cxx |   30 +++++++++++++-------------
 1 file changed, 15 insertions(+), 15 deletions(-)

New commits:
commit 049189f49dba87e0b6d948e2b6a5e416f1fca36b
Author:     Eike Rathke <erack at redhat.com>
AuthorDate: Fri Jun 28 18:02:38 2019 +0200
Commit:     Eike Rathke <erack at redhat.com>
CommitDate: Fri Jun 28 20:49:29 2019 +0200

    Use LanguageTag::getFallbackStrings() instead of old dumb hard coded stuff
    
    So finding correct offline help will actually work with language
    tags containing scripts or variants.
    
    Change-Id: I493041fbfe62dc7cd2e035592fe94ef9fe3c2480
    Reviewed-on: https://gerrit.libreoffice.org/74855
    Reviewed-by: Eike Rathke <erack at redhat.com>
    Tested-by: Jenkins

diff --git a/xmlhelp/source/cxxhelp/provider/databases.cxx b/xmlhelp/source/cxxhelp/provider/databases.cxx
index 9f75248910b6..04aba4c5991e 100644
--- a/xmlhelp/source/cxxhelp/provider/databases.cxx
+++ b/xmlhelp/source/cxxhelp/provider/databases.cxx
@@ -400,23 +400,23 @@ OUString Databases::processLang( const OUString& Language )
 
     if( it == m_aLangSet.end() )
     {
-        sal_Int32 idx;
-        osl::DirectoryItem aDirItem;
+        // XXX the old code looked for '-' and '_' as separator between
+        // language and country, no idea if '_' actually still can happen
+        // (probably not), but play safe and keep that and transform to proper
+        // BCP47.
+        const OUString aBcp47( Language.replaceAll( "_", "-"));
 
-        if( osl::FileBase::E_None == osl::DirectoryItem::get( getInstallPathAsURL() + Language,aDirItem ) )
-        {
-            ret = Language;
-            m_aLangSet[ Language ] = ret;
-        }
-        /* FIXME-BCP47: this is wrong, does not work as soon as script or
-         * variant is involved in the language tag. */
-        else if( ( ( idx = Language.indexOf( '-' ) ) != -1 ||
-                   ( idx = Language.indexOf( '_' ) ) != -1 ) &&
-                    osl::FileBase::E_None == osl::DirectoryItem::get( getInstallPathAsURL() + Language.copy( 0,idx ),
-                                                                   aDirItem ) )
+        // Try if language tag or fallbacks are installed.
+        osl::DirectoryItem aDirItem;
+        std::vector<OUString> aFallbacks( LanguageTag( aBcp47).getFallbackStrings(true));
+        for (auto const & rFB : aFallbacks)
         {
-            ret = Language.copy( 0,idx );
-            m_aLangSet[ Language ] = ret;
+            if (osl::FileBase::E_None == osl::DirectoryItem::get( getInstallPathAsURL() + rFB, aDirItem))
+            {
+                ret = rFB;
+                m_aLangSet[ Language ] = ret;
+                break;  // for
+            }
         }
     }
     else


More information about the Libreoffice-commits mailing list