summaryrefslogtreecommitdiff
path: root/desktop
diff options
context:
space:
mode:
authorXisco Fauli <xiscofauli@libreoffice.org>2023-07-12 07:03:15 +0200
committerXisco Fauli <xiscofauli@libreoffice.org>2023-07-12 08:57:41 +0200
commit94e6049b6467d9bc1e52a1a80c7cf1a5f138e82d (patch)
treedf20b3feac049ae0f8361ccfbb3d4f9f2a172a91 /desktop
parente78f60a369146774ca2a38ca121f294b562b2be5 (diff)
Revert recent LanguageTool commits
Reason for revert: See discussion in https://gerrit.libreoffice.org/c/core/+/154302 - it's causing CppunitTest_sw_layoutwriter2 to fail on Windows. - it's causing CppunitTest_sw_layoutwriter to fail on Linux. - Probably other recent CI failures are also related. - A similar commit was reverted one year ago for similar reasons -> https://gerrit.libreoffice.org/c/core/+/135859 This commit contains the following commits: Revert "lok: remove old hack for LanguageTool locales" This reverts commit 9a5329a266bd74abc4794f1fcbae3db07582dbde. Revert "lok: LanguageTool provides list of languages" This reverts commit 21d0489a5efa970e975ce1a70dfda2fd9e2c186d. Revert "lok: remove duplicated locales for LanguageTool" This reverts commit a0865169ab62508a7b933ed4634defa57b25f7b7. Revert "Load the locales from config file for languagetool" This reverts commit 81b0d9a951c9b15f4f1a76d45d0bd955b4dfc95b. Change-Id: I3dc48097615f510e33e233e868b6b10704d81e67 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/154342 Tested-by: Jenkins Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
Diffstat (limited to 'desktop')
-rw-r--r--desktop/source/lib/init.cxx195
1 files changed, 149 insertions, 46 deletions
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index 4f1b5287130f..dbd236858ce8 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -117,7 +117,6 @@
#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>
@@ -228,8 +227,6 @@ using namespace vcl;
using namespace desktop;
using namespace utl;
-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;
@@ -5620,6 +5617,132 @@ 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");
@@ -5637,28 +5760,12 @@ 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(const char* pCommand)
+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())
{
@@ -5667,24 +5774,33 @@ static char* getLanguages(const char* pCommand)
aLocales = xSpell->getLocales();
}
- // LanguageTool
- if (LanguageToolCfg::IsEnabled::get())
+ /* 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::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();
+ uno::Sequence< css::lang::Locale > aSeq;
+ getDocLanguages(pThis, aSeq);
+ aLocales = aSeq;
}
}
boost::property_tree::ptree aTree;
aTree.put("commandName", pCommand);
boost::property_tree::ptree aValues;
- 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);
+ 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));
+ }
aTree.add_child("commandValues", aValues);
std::stringstream aStream;
boost::property_tree::write_json(aStream, aTree);
@@ -6023,7 +6139,7 @@ static char* doc_getCommandValues(LibreOfficeKitDocument* pThis, const char* pCo
if (!strcmp(pCommand, ".uno:LanguageStatus"))
{
- return getLanguages(pCommand);
+ return getLanguages(pThis, pCommand);
}
else if (!strcmp(pCommand, ".uno:CharFontName"))
{
@@ -7160,8 +7276,6 @@ static void preLoadShortCutAccelerators()
batch->commit();
}
-void setLanguageToolConfig();
-
/// Used only by LibreOfficeKit when used by Online to pre-initialize
static void preloadData()
{
@@ -7180,9 +7294,6 @@ 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());
@@ -7402,19 +7513,11 @@ 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++)
{
- // turn off spell checker if LanguageTool supports the locale already
- if (xSuppLoc->hasLocale(aLocales[itLocale]))
- xLangSrv->setConfiguredServices(cSpell, aLocales[itLocale], aEmpty);
+ xLangSrv->setConfiguredServices(SN_SPELLCHECKER, aLocales[itLocale], aEmpty);
}
}
}