summaryrefslogtreecommitdiff
path: root/desktop/source
diff options
context:
space:
mode:
authorSzymon Kłos <szymon.klos@collabora.com>2023-02-08 11:10:58 +0100
committerAndras Timar <andras.timar@collabora.com>2023-02-10 21:55:43 +0000
commit6d76656a2858a792a0ff59fda5708145c500eae7 (patch)
treea51e7d7e569b8e3ec8be46f51b0ed8b67891e852 /desktop/source
parent88e1e8fb06180fe070aaf0065d9c3403b477cfd7 (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 Change-Id: Id9de8519303774163721def8661fa408da449348 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/146665 Reviewed-by: Henry Castro <hcastro@collabora.com> Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Diffstat (limited to 'desktop/source')
-rw-r--r--desktop/source/lib/init.cxx64
1 files changed, 48 insertions, 16 deletions
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index ec7b82ef086f..2d79b7e57d3a 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -104,6 +104,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>
@@ -5538,12 +5539,28 @@ static void doc_resetSelection(LibreOfficeKitDocument* pThis)
pDoc->resetSelection();
}
+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())
{
@@ -5552,6 +5569,19 @@ static char* getLanguages(LibreOfficeKitDocument* pThis, const char* pCommand)
aLocales = xSpell->getLocales();
}
+ // LanguageTool
+ SvxLanguageToolOptions& rLanguageOpts = SvxLanguageToolOptions::Get();
+ if (rLanguageOpts.getEnabled())
+ {
+ 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 */
@@ -5564,19 +5594,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);
@@ -6999,6 +7020,8 @@ static void lo_status_indicator_callback(void *data, comphelper::LibreOfficeKit:
}
}
+void setLanguageToolConfig();
+
/// Used only by LibreOfficeKit when used by Online to pre-initialize
static void preloadData()
{
@@ -7017,6 +7040,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());
@@ -7202,12 +7228,19 @@ void setLanguageToolConfig()
if (xSpell.is())
{
Sequence<OUString> aEmpty;
- constexpr OUStringLiteral cSpell(SN_SPELLCHECKER);
+ 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(cSpell, aLocales[itLocale], aEmpty);
+ // turn off spell checker if LanguageTool supports the locale already
+ if (xSuppLoc->hasLocale(aLocales[itLocale]))
+ xLangSrv->setConfiguredServices(cSpell, aLocales[itLocale], aEmpty);
}
}
}
@@ -7562,7 +7595,6 @@ static int lo_initialize(LibreOfficeKit* pThis, const char* pAppPath, const char
#endif
setCertificateDir();
- setLanguageToolConfig();
setDeeplConfig();
if (bNotebookbar)