diff options
author | Szymon Kłos <szymon.klos@collabora.com> | 2023-02-08 11:10:58 +0100 |
---|---|---|
committer | Andras Timar <andras.timar@collabora.com> | 2023-07-05 09:12:22 +0200 |
commit | e2bb227d0762a4200ce6f064f7b53911c6d16fdf (patch) | |
tree | 781f2cd803aae1f2cf17da5961a8102c69fc6761 /desktop | |
parent | 84bdf9e81a63a8bd308709c86b51bf3900a23c50 (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>
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>
Diffstat (limited to 'desktop')
-rw-r--r-- | desktop/source/lib/init.cxx | 62 |
1 files changed, 48 insertions, 14 deletions
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx index 5d957a9c89be..26b44a25b941 100644 --- a/desktop/source/lib/init.cxx +++ b/desktop/source/lib/init.cxx @@ -117,6 +117,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> @@ -5739,12 +5740,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()) { @@ -5753,6 +5770,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 */ @@ -5767,19 +5797,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); @@ -7243,6 +7264,8 @@ static void preLoadShortCutAccelerators() batch->commit(); } +void setLanguageToolConfig(); + /// Used only by LibreOfficeKit when used by Online to pre-initialize static void preloadData() { @@ -7261,6 +7284,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()); @@ -7489,11 +7515,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); } } } |