summaryrefslogtreecommitdiff
path: root/desktop
diff options
context:
space:
mode:
authorSzymon Kłos <szymon.klos@collabora.com>2023-02-08 11:10:58 +0100
committerCaolán McNamara <caolan.mcnamara@collabora.com>2023-10-22 19:02:13 +0200
commitb9a081654b709e8572673c5ac728b76d6e968f98 (patch)
treed93a7ca6c8231c0e3dbccabb2418ba48d038ff00 /desktop
parent7fbea38b7aa5335abef55b445df88ee571d18360 (diff)
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 <hcastro@collabora.com> Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/153960 Reviewed-by: Andras Timar <andras.timar@collabora.com> Tested-by: Andras Timar <andras.timar@collabora.com> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/154161 Tested-by: Jenkins Reviewed-by: Szymon Kłos <szymon.klos@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.mcnamara@collabora.com>
Diffstat (limited to 'desktop')
-rw-r--r--desktop/source/lib/init.cxx63
1 files changed, 49 insertions, 14 deletions
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);
}
}
}