desktop/source/lib/init.cxx                                        |  195 
++--------
 include/unotools/lingucfg.hxx                                      |    2 
 lingucomponent/config/Linguistic-lingucomponent-grammarchecker.xcu |   30 +
 lingucomponent/source/spellcheck/languagetool/languagetoolimp.cxx  |   58 +-
 postprocess/CustomTarget_registry.mk                               |    1 
 unotools/source/config/lingucfg.cxx                                |   21 +
 6 files changed, 123 insertions(+), 184 deletions(-)

New commits:
commit ef5afb766553dfa9bf1c577e5f6bcb5bf5412782
Author:     Szymon Kłos <szymon.k...@collabora.com>
AuthorDate: Fri Feb 10 14:56:06 2023 +0100
Commit:     Caolán McNamara <caolan.mcnam...@collabora.com>
CommitDate: Sun Oct 22 19:02:19 2023 +0200

    lok: remove old hack for LanguageTool locales
    
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/146779
    Reviewed-by: Henry Castro <hcas...@collabora.com>
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/153962
    Reviewed-by: Andras Timar <andras.ti...@collabora.com>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/154162
    Tested-by: Jenkins
    Reviewed-by: Szymon Kłos <szymon.k...@collabora.com>
    (cherry picked from commit 9a5329a266bd74abc4794f1fcbae3db07582dbde)
    Change-Id: I44cc4a5b1a0d92e2b0857cdc1d68c931ab95c0d3
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/158332
    Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com>

diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index 2fdeaf2d18f0..880374e2d0f5 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -5864,132 +5864,6 @@ static void 
doc_setGraphicSelection(LibreOfficeKitDocument* pThis, int nType, in
     pDoc->setGraphicSelection(nType, nX, nY);
 }
 
-static void getDocLanguages(LibreOfficeKitDocument* pThis, 
uno::Sequence<lang::Locale>& rSeq)
-{
-    SfxViewFrame* pViewFrame = SfxViewFrame::Current();
-    if (!pViewFrame)
-        return;
-
-    SfxDispatcher* pDispatcher = pViewFrame->GetBindings().GetDispatcher();
-    if (!pDispatcher)
-        return;
-
-    css::uno::Any aLangStatus;
-    pDispatcher->QueryState(SID_LANGUAGE_STATUS, aLangStatus);
-
-    OUString sCurrent;
-    OUString sKeyboard;
-    OUString sGuessText;
-    SvtScriptType eScriptType = SvtScriptType::LATIN | SvtScriptType::ASIAN
-        | SvtScriptType::COMPLEX;
-
-    Sequence<OUString> aSeqLang;
-    if (aLangStatus >>= aSeqLang)
-    {
-        if (aSeqLang.getLength() == 4)
-        {
-            sCurrent = aSeqLang[0];
-            eScriptType = static_cast<SvtScriptType>(aSeqLang[1].toInt32());
-            sKeyboard = aSeqLang[1];
-            sGuessText = aSeqLang[2];
-        }
-    }
-    else
-    {
-        aLangStatus >>= sCurrent;
-    }
-
-    LanguageType nLangType;
-    std::set<LanguageType> aLangItems;
-
-    if (!sCurrent.isEmpty())
-    {
-        nLangType = SvtLanguageTable::GetLanguageType(sCurrent);
-        if (nLangType != LANGUAGE_DONTKNOW)
-        {
-            aLangItems.insert(nLangType);
-        }
-    }
-
-    const AllSettings& rAllSettings = Application::GetSettings();
-    nLangType = rAllSettings.GetLanguageTag().getLanguageType();
-    if (nLangType != LANGUAGE_DONTKNOW &&
-        (eScriptType & SvtLanguageOptions::GetScriptTypeOfLanguage(nLangType)))
-    {
-        aLangItems.insert(nLangType);
-    }
-
-    nLangType = rAllSettings.GetUILanguageTag().getLanguageType();
-    if (nLangType != LANGUAGE_DONTKNOW &&
-        (eScriptType & SvtLanguageOptions::GetScriptTypeOfLanguage(nLangType)))
-    {
-        aLangItems.insert(nLangType);
-    }
-
-    if (!sKeyboard.isEmpty())
-    {
-        nLangType = SvtLanguageTable::GetLanguageType(sKeyboard);
-        if (nLangType != LANGUAGE_DONTKNOW &&
-            (eScriptType & 
SvtLanguageOptions::GetScriptTypeOfLanguage(nLangType)))
-        {
-            aLangItems.insert(nLangType);
-        }
-    }
-
-    if (!sGuessText.isEmpty())
-    {
-        Reference<linguistic2::XLanguageGuessing> xLangGuesser;
-        try
-        {
-            xLangGuesser = linguistic2::LanguageGuessing::create(xContext);
-        }
-        catch(...)
-        {
-        }
-
-        if (xLangGuesser.is())
-        {
-            lang::Locale aLocale = 
xLangGuesser->guessPrimaryLanguage(sGuessText, 0,
-                                                                      
sGuessText.getLength());
-            LanguageTag aLanguageTag(aLocale);
-            nLangType = aLanguageTag.getLanguageType(false);
-            if (nLangType != LANGUAGE_DONTKNOW &&
-                (eScriptType & 
SvtLanguageOptions::GetScriptTypeOfLanguage(nLangType)))
-            {
-                aLangItems.insert(nLangType);
-            }
-        }
-    }
-
-    LibLODocument_Impl* pDocument = static_cast<LibLODocument_Impl*>(pThis);
-    Reference<document::XDocumentLanguages> 
xDocumentLanguages(pDocument->mxComponent, UNO_QUERY);
-    if (xDocumentLanguages.is())
-    {
-        const Sequence<lang::Locale> 
aLocales(xDocumentLanguages->getDocumentLanguages(
-                                                  
static_cast<sal_Int16>(eScriptType), 64));
-
-        for (const lang::Locale& aLocale : aLocales)
-        {
-            nLangType = SvtLanguageTable::GetLanguageType(aLocale.Language);
-            if (nLangType != LANGUAGE_DONTKNOW &&
-                (eScriptType & 
SvtLanguageOptions::GetScriptTypeOfLanguage(nLangType)))
-            {
-                aLangItems.insert(nLangType);
-            }
-        }
-    }
-
-    int nLocale = 0;
-    Sequence<lang::Locale> aLocales(aLangItems.size());
-    auto pLocales = aLocales.getArray();
-    for (const LanguageType& itLang : aLangItems)
-    {
-        pLocales[nLocale++] = LanguageTag::convertToLocale(itLang);
-    }
-
-    rSeq = aLocales;
-}
-
 static void doc_resetSelection(LibreOfficeKitDocument* pThis)
 {
     comphelper::ProfileZone aZone("doc_resetSelection");
@@ -6050,7 +5924,7 @@ static void addLocale(boost::property_tree::ptree& 
rValues, css::lang::Locale co
     rValues.push_back(std::make_pair("", aChild));
 }
 
-static char* getLanguages(LibreOfficeKitDocument* pThis, const char* pCommand)
+static char* getLanguages(const char* pCommand)
 {
     css::uno::Sequence< css::lang::Locale > aLocales;
     css::uno::Sequence< css::lang::Locale > aGrammarLocales;
@@ -6075,18 +5949,6 @@ static char* getLanguages(LibreOfficeKitDocument* pThis, 
const char* pCommand)
             uno::Reference< linguistic2::XSupportedLocales > xSuppLoc( xGC, 
uno::UNO_QUERY_THROW );
             aGrammarLocales = xSuppLoc->getLocales();
         }
-
-        // Fallback
-
-        /* FIXME: To obtain the document languages the spell checker can be 
disabled,
-           so a future re-work of the getLanguages function is needed in favor 
to use
-           getDocLanguages */
-        if (!aLocales.hasElements())
-        {
-            uno::Sequence< css::lang::Locale > aSeq;
-            getDocLanguages(pThis, aSeq);
-            aLocales = aSeq;
-        }
     }
 
     boost::property_tree::ptree aTree;
@@ -6438,7 +6300,7 @@ static char* doc_getCommandValues(LibreOfficeKitDocument* 
pThis, const char* pCo
     }
     else if (!strcmp(pCommand, ".uno:LanguageStatus"))
     {
-        return getLanguages(pThis, pCommand);
+        return getLanguages(pCommand);
     }
     else if (!strcmp(pCommand, ".uno:CharFontName"))
     {
commit b9a081654b709e8572673c5ac728b76d6e968f98
Author:     Szymon Kłos <szymon.k...@collabora.com>
AuthorDate: Wed Feb 8 11:10:58 2023 +0100
Commit:     Caolán McNamara <caolan.mcnam...@collabora.com>
CommitDate: Sun Oct 22 19:02:13 2023 +0200

    lok: LanguageTool provides list of languages
    
    - it sends supported list to the LOK client
    - disables Spell Checker for locales supported by LanguageTool
    - duden protocol supports only german
    - initialize language tool config before usage to fetch correct
      list of supported languages
    
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/146665
    Reviewed-by: Henry Castro <hcas...@collabora.com>
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/153960
    Reviewed-by: Andras Timar <andras.ti...@collabora.com>
    Tested-by: Andras Timar <andras.ti...@collabora.com>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/154161
    Tested-by: Jenkins
    Reviewed-by: Szymon Kłos <szymon.k...@collabora.com>
    (cherry picked from commit 21d0489a5efa970e975ce1a70dfda2fd9e2c186d)
    Change-Id: Id0f909fbd2cca47e93ed8632217a45b5087c1ecf
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/158331
    Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com>

diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index 57869a7540ef..2fdeaf2d18f0 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -128,6 +128,7 @@
 #include <com/sun/star/linguistic2/LanguageGuessing.hpp>
 #include <com/sun/star/linguistic2/LinguServiceManager.hpp>
 #include <com/sun/star/linguistic2/XSpellChecker.hpp>
+#include <com/sun/star/linguistic2/XProofreader.hpp>
 #include <com/sun/star/i18n/LocaleCalendar2.hpp>
 #include <com/sun/star/i18n/ScriptType.hpp>
 #include <com/sun/star/lang/DisposedException.hpp>
@@ -242,6 +243,8 @@ using namespace bridge;
 using namespace uno;
 using namespace lang;
 
+using LanguageToolCfg = 
officecfg::Office::Linguistic::GrammarChecking::LanguageTool;
+
 static LibLibreOffice_Impl *gImpl = nullptr;
 static bool lok_preinit_2_called = false;
 static std::weak_ptr< LibreOfficeKitClass > gOfficeClass;
@@ -6033,12 +6036,28 @@ static char* getDocReadOnly(LibreOfficeKitDocument* 
pThis)
     return pJson;
 }
 
+static void addLocale(boost::property_tree::ptree& rValues, css::lang::Locale 
const & rLocale)
+{
+    boost::property_tree::ptree aChild;
+    OUString sLanguage;
+    const LanguageTag aLanguageTag( rLocale );
+    sLanguage = 
SvtLanguageTable::GetLanguageString(aLanguageTag.getLanguageType());
+    if (sLanguage.endsWith("}"))
+        return;
+
+    sLanguage += ";" + aLanguageTag.getBcp47(false);
+    aChild.put("", sLanguage.toUtf8());
+    rValues.push_back(std::make_pair("", aChild));
+}
+
 static char* getLanguages(LibreOfficeKitDocument* pThis, const char* pCommand)
 {
     css::uno::Sequence< css::lang::Locale > aLocales;
+    css::uno::Sequence< css::lang::Locale > aGrammarLocales;
 
     if (xContext.is())
     {
+        // SpellChecker
         css::uno::Reference<css::linguistic2::XLinguServiceManager2> xLangSrv 
= css::linguistic2::LinguServiceManager::create(xContext);
         if (xLangSrv.is())
         {
@@ -6047,6 +6066,18 @@ static char* getLanguages(LibreOfficeKitDocument* pThis, 
const char* pCommand)
                 aLocales = xSpell->getLocales();
         }
 
+        // LanguageTool
+        if (LanguageToolCfg::IsEnabled::get())
+        {
+            uno::Reference< linguistic2::XProofreader > xGC(
+                    
xContext->getServiceManager()->createInstanceWithContext("org.openoffice.lingu.LanguageToolGrammarChecker",
 xContext),
+                    uno::UNO_QUERY_THROW );
+            uno::Reference< linguistic2::XSupportedLocales > xSuppLoc( xGC, 
uno::UNO_QUERY_THROW );
+            aGrammarLocales = xSuppLoc->getLocales();
+        }
+
+        // Fallback
+
         /* FIXME: To obtain the document languages the spell checker can be 
disabled,
            so a future re-work of the getLanguages function is needed in favor 
to use
            getDocLanguages */
@@ -6061,19 +6092,10 @@ static char* getLanguages(LibreOfficeKitDocument* 
pThis, const char* pCommand)
     boost::property_tree::ptree aTree;
     aTree.put("commandName", pCommand);
     boost::property_tree::ptree aValues;
-    boost::property_tree::ptree aChild;
-    OUString sLanguage;
-    for ( css::lang::Locale const & locale : std::as_const(aLocales) )
-    {
-        const LanguageTag aLanguageTag( locale );
-        sLanguage = 
SvtLanguageTable::GetLanguageString(aLanguageTag.getLanguageType());
-        if (sLanguage.startsWith("{") && sLanguage.endsWith("}"))
-            continue;
-
-        sLanguage += ";" + aLanguageTag.getBcp47(false);
-        aChild.put("", sLanguage.toUtf8());
-        aValues.push_back(std::make_pair("", aChild));
-    }
+    for ( css::lang::Locale const & rLocale : std::as_const(aLocales) )
+        addLocale(aValues, rLocale);
+    for ( css::lang::Locale const & rLocale : std::as_const(aGrammarLocales) )
+        addLocale(aValues, rLocale);
     aTree.add_child("commandValues", aValues);
     std::stringstream aStream;
     boost::property_tree::write_json(aStream, aTree);
@@ -7542,6 +7564,8 @@ static void preLoadShortCutAccelerators()
     batch->commit();
 }
 
+void setLanguageToolConfig();
+
 /// Used only by LibreOfficeKit when used by Online to pre-initialize
 static void preloadData()
 {
@@ -7560,6 +7584,9 @@ static void preloadData()
     if(bAbort)
         std::cerr << "CheckExtensionDependencies failed" << std::endl;
 
+    // setup LanguageTool config before spell checking init
+    setLanguageToolConfig();
+
     // preload all available dictionaries
     css::uno::Reference<css::linguistic2::XLinguServiceManager> xLngSvcMgr =
         
css::linguistic2::LinguServiceManager::create(comphelper::getProcessComponentContext());
@@ -7814,11 +7841,19 @@ void setLanguageToolConfig()
                 if (xSpell.is())
                 {
                     Sequence<OUString> aEmpty;
+                    static constexpr OUStringLiteral cSpell(SN_SPELLCHECKER);
                     Sequence<css::lang::Locale> aLocales = 
xSpell->getLocales();
 
+                    uno::Reference<linguistic2::XProofreader> xGC(
+                        
xContext->getServiceManager()->createInstanceWithContext("org.openoffice.lingu.LanguageToolGrammarChecker",
 xContext),
+                        uno::UNO_QUERY_THROW);
+                    uno::Reference<linguistic2::XSupportedLocales> 
xSuppLoc(xGC, uno::UNO_QUERY_THROW);
+
                     for (int itLocale = 0; itLocale < aLocales.getLength(); 
itLocale++)
                     {
-                        xLangSrv->setConfiguredServices(SN_SPELLCHECKER, 
aLocales[itLocale], aEmpty);
+                        // turn off spell checker if LanguageTool supports the 
locale already
+                        if (xSuppLoc->hasLocale(aLocales[itLocale]))
+                            xLangSrv->setConfiguredServices(cSpell, 
aLocales[itLocale], aEmpty);
                     }
                 }
             }
diff --git a/lingucomponent/source/spellcheck/languagetool/languagetoolimp.cxx 
b/lingucomponent/source/spellcheck/languagetool/languagetoolimp.cxx
index c4c4b6379a5f..d1c87af5fa0a 100644
--- a/lingucomponent/source/spellcheck/languagetool/languagetoolimp.cxx
+++ b/lingucomponent/source/spellcheck/languagetool/languagetoolimp.cxx
@@ -56,6 +56,8 @@ using namespace com::sun::star::beans;
 using namespace com::sun::star::lang;
 using namespace com::sun::star::linguistic2;
 
+constexpr OUStringLiteral sDuden = u"duden";
+
 namespace
 {
 constexpr size_t MAX_SUGGESTIONS_SIZE = 10;
@@ -338,8 +340,17 @@ uno::Sequence<Locale> SAL_CALL 
LanguageToolGrammarChecker::getLocales()
 
     SvtLinguConfig aLinguCfg;
     uno::Sequence<OUString> aLocaleList;
-    aLinguCfg.GetLocaleListFor("GrammarCheckers", 
"org.openoffice.lingu.LanguageToolGrammarChecker",
-                               aLocaleList);
+
+    if (LanguageToolCfg::RestProtocol::get().value_or("") == sDuden)
+    {
+        aLocaleList.realloc(3);
+        aLocaleList.getArray()[0] = "de-DE";
+        aLocaleList.getArray()[1] = "en-US";
+        aLocaleList.getArray()[2] = "en-GB";
+    }
+    else
+        aLinguCfg.GetLocaleListFor("GrammarCheckers",
+                                   
"org.openoffice.lingu.LanguageToolGrammarChecker", aLocaleList);
 
     auto nLength = aLocaleList.getLength();
     m_aSuppLocales.realloc(nLength);
commit 7fbea38b7aa5335abef55b445df88ee571d18360
Author:     Mert Tumer <mert.tu...@collabora.com>
AuthorDate: Tue May 10 13:06:06 2022 +0300
Commit:     Caolán McNamara <caolan.mcnam...@collabora.com>
CommitDate: Sun Oct 22 19:02:06 2023 +0200

    Load the locales from config file for languagetool
    
    Locales needs to be read again
    in the Preferences/Writing Aids section and since
    this is a network operation it can cause a problem.
    Better to list all the supported locales in the xcu
    and load it right away.
    
    Signed-off-by: Mert Tumer <mert.tu...@collabora.com>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135598
    Tested-by: Jenkins
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/153959
    Reviewed-by: Andras Timar <andras.ti...@collabora.com>
    Tested-by: Andras Timar <andras.ti...@collabora.com>
    (cherry picked from commit 84bdf9e81a63a8bd308709c86b51bf3900a23c50)
    Change-Id: Iad9201101aa167ad33f479c67f72649786e1f2cf
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/158330
    Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com>

diff --git a/include/unotools/lingucfg.hxx b/include/unotools/lingucfg.hxx
index 40797a372f33..c924d7898764 100644
--- a/include/unotools/lingucfg.hxx
+++ b/include/unotools/lingucfg.hxx
@@ -196,6 +196,8 @@ public:
 
     bool GetDictionaryEntry( const OUString &rNodeName, 
SvtLinguConfigDictionaryEntry &rDicEntry ) const;
 
+    bool GetLocaleListFor( const OUString &rSetName, const OUString 
&rSetEntry, css::uno::Sequence< OUString > &rLocaleList ) const;
+
     css::uno::Sequence< OUString > GetDisabledDictionaries() const;
 
     std::vector< SvtLinguConfigDictionaryEntry > 
GetActiveDictionariesByFormat( std::u16string_view rFormatName ) const;
diff --git a/lingucomponent/config/Linguistic-lingucomponent-grammarchecker.xcu 
b/lingucomponent/config/Linguistic-lingucomponent-grammarchecker.xcu
new file mode 100644
index 000000000000..6fa455d969b8
--- /dev/null
+++ b/lingucomponent/config/Linguistic-lingucomponent-grammarchecker.xcu
@@ -0,0 +1,30 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!--
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ *   Licensed to the Apache Software Foundation (ASF) under one or more
+ *   contributor license agreements. See the NOTICE file distributed
+ *   with this work for additional information regarding copyright
+ *   ownership. The ASF licenses this file to you under the Apache
+ *   License, Version 2.0 (the "License"); you may not use this file
+ *   except in compliance with the License. You may obtain a copy of
+ *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
+-->
+<oor:component-data oor:name="Linguistic" oor:package="org.openoffice.Office" 
xmlns:install="http://openoffice.org/2004/installation"; 
xmlns:oor="http://openoffice.org/2001/registry"; 
xmlns:xs="http://www.w3.org/2001/XMLSchema"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";>
+    <node oor:name="ServiceManager">
+        <node oor:name="GrammarCheckers">
+            <node oor:name="org.openoffice.lingu.LanguageToolGrammarChecker" 
oor:op="fuse">
+                <prop oor:name="Locales" oor:type="oor:string-list">
+                    <value>ar ast-ES be-BY br-FR ca-ES ca-ES-valencia zh-CN 
da-DK nl nl-BE en en-AU en-CA en-GB en-NZ en-ZA en-US fr gl-ES de de-AT de-DE 
de-CH el-GR ga-IE it ja-JP km-KH nb no fa pl-PL pt pt-AO pt-BR pt-MZ pt-PT 
ro-RO ru-RU de-DE-x-simple-language sk-SK sl-SI es es-AR sv tl-PH ta-IN 
uk-UA</value>
+                </prop>
+            </node>
+        </node>
+    </node>
+</oor:component-data>
+
diff --git a/lingucomponent/source/spellcheck/languagetool/languagetoolimp.cxx 
b/lingucomponent/source/spellcheck/languagetool/languagetoolimp.cxx
index 7152a6ff0880..c4c4b6379a5f 100644
--- a/lingucomponent/source/spellcheck/languagetool/languagetoolimp.cxx
+++ b/lingucomponent/source/spellcheck/languagetool/languagetoolimp.cxx
@@ -295,14 +295,6 @@ void parseProofreadingJSONResponse(ProofreadingResult& 
rResult, std::string&& aJ
         });
 }
 
-OUString getLocaleListURL()
-{
-    if (auto oURL = LanguageToolCfg::BaseURL::get())
-        if (!oURL->isEmpty())
-            return *oURL + "/languages";
-    return {};
-}
-
 OUString getCheckerURL()
 {
     if (auto oURL = LanguageToolCfg::BaseURL::get())
@@ -336,44 +328,29 @@ sal_Bool SAL_CALL 
LanguageToolGrammarChecker::hasLocale(const Locale& rLocale)
 
 uno::Sequence<Locale> SAL_CALL LanguageToolGrammarChecker::getLocales()
 {
+    osl::MutexGuard aGuard(linguistic::GetLinguMutex());
+
     if (m_aSuppLocales.hasElements())
         return m_aSuppLocales;
+
     if (!LanguageToolCfg::IsEnabled::get())
-    {
         return m_aSuppLocales;
-    }
 
-    OUString localeUrl = getLocaleListURL();
-    if (localeUrl.isEmpty())
-    {
-        return m_aSuppLocales;
-    }
-    tools::Long statusCode = 0;
-    std::string response = makeHttpRequest(localeUrl, HTTP_METHOD::HTTP_GET, 
OString(), statusCode);
-    if (statusCode != 200)
-    {
-        return m_aSuppLocales;
-    }
-    if (response.empty())
-    {
-        return m_aSuppLocales;
-    }
-    boost::property_tree::ptree root;
-    std::stringstream aStream(response);
-    boost::property_tree::read_json(aStream, root);
+    SvtLinguConfig aLinguCfg;
+    uno::Sequence<OUString> aLocaleList;
+    aLinguCfg.GetLocaleListFor("GrammarCheckers", 
"org.openoffice.lingu.LanguageToolGrammarChecker",
+                               aLocaleList);
 
-    size_t length = root.size();
-    m_aSuppLocales.realloc(length);
+    auto nLength = aLocaleList.getLength();
+    m_aSuppLocales.realloc(nLength);
     auto pArray = m_aSuppLocales.getArray();
-    int i = 0;
-    for (auto it = root.begin(); it != root.end(); it++, i++)
+    auto pLocaleList = aLocaleList.getArray();
+
+    for (auto i = 0; i < nLength; i++)
     {
-        boost::property_tree::ptree& localeItem = it->second;
-        const std::string longCode = localeItem.get<std::string>("longCode");
-        Locale aLocale = LanguageTag::convertToLocale(
-            OUString(longCode.c_str(), longCode.length(), 
RTL_TEXTENCODING_UTF8));
-        pArray[i] = aLocale;
+        pArray[i] = LanguageTag::convertToLocale(pLocaleList[i]);
     }
+
     return m_aSuppLocales;
 }
 
diff --git a/postprocess/CustomTarget_registry.mk 
b/postprocess/CustomTarget_registry.mk
index b0bc7a4320f2..9e235f098b25 100644
--- a/postprocess/CustomTarget_registry.mk
+++ b/postprocess/CustomTarget_registry.mk
@@ -116,6 +116,7 @@ postprocess_DEPS_lingucomponent := main
 postprocess_FILES_lingucomponent := \
        
$(SRCDIR)/lingucomponent/config/Linguistic-lingucomponent-hyphenator.xcu \
        
$(SRCDIR)/lingucomponent/config/Linguistic-lingucomponent-spellchecker.xcu \
+       
$(SRCDIR)/lingucomponent/config/Linguistic-lingucomponent-grammarchecker.xcu \
        $(SRCDIR)/lingucomponent/config/Linguistic-lingucomponent-thesaurus.xcu 
\
 
 postprocess_FILES_main := \
diff --git a/unotools/source/config/lingucfg.cxx 
b/unotools/source/config/lingucfg.cxx
index 571601e1663a..1a4172c7844a 100644
--- a/unotools/source/config/lingucfg.cxx
+++ b/unotools/source/config/lingucfg.cxx
@@ -941,6 +941,27 @@ bool SvtLinguConfig::GetSupportedDictionaryFormatsFor(
     return bSuccess;
 }
 
+bool SvtLinguConfig::GetLocaleListFor( const OUString &rSetName, const 
OUString &rSetEntry, css::uno::Sequence< OUString > &rLocaleList ) const
+{
+    if (rSetName.isEmpty() || rSetEntry.isEmpty())
+        return false;
+    bool bSuccess = false;
+    try
+    {
+        uno::Reference< container::XNameAccess > xNA( GetMainUpdateAccess(), 
uno::UNO_QUERY_THROW );
+        xNA.set( xNA->getByName("ServiceManager"), uno::UNO_QUERY_THROW );
+        xNA.set( xNA->getByName( rSetName ), uno::UNO_QUERY_THROW );
+        xNA.set( xNA->getByName( rSetEntry ), uno::UNO_QUERY_THROW );
+        if (xNA->getByName( "Locales" ) >>= rLocaleList)
+            bSuccess = true;
+        DBG_ASSERT( rLocaleList.hasElements(), "Locale list is empty" );
+    }
+    catch (uno::Exception &)
+    {
+    }
+    return bSuccess;
+}
+
 static bool lcl_GetFileUrlFromOrigin(
     OUString /*out*/ &rFileUrl,
     const OUString &rOrigin )

Reply via email to