diff options
author | Xisco Fauli <xiscofauli@libreoffice.org> | 2023-07-12 07:03:15 +0200 |
---|---|---|
committer | Xisco Fauli <xiscofauli@libreoffice.org> | 2023-07-12 08:57:41 +0200 |
commit | 94e6049b6467d9bc1e52a1a80c7cf1a5f138e82d (patch) | |
tree | df20b3feac049ae0f8361ccfbb3d4f9f2a172a91 /lingucomponent | |
parent | e78f60a369146774ca2a38ca121f294b562b2be5 (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 'lingucomponent')
-rw-r--r-- | lingucomponent/config/Linguistic-lingucomponent-grammarchecker.xcu | 30 | ||||
-rw-r--r-- | lingucomponent/source/spellcheck/languagetool/languagetoolimp.cxx | 59 |
2 files changed, 37 insertions, 52 deletions
diff --git a/lingucomponent/config/Linguistic-lingucomponent-grammarchecker.xcu b/lingucomponent/config/Linguistic-lingucomponent-grammarchecker.xcu deleted file mode 100644 index 6fa455d969b8..000000000000 --- a/lingucomponent/config/Linguistic-lingucomponent-grammarchecker.xcu +++ /dev/null @@ -1,30 +0,0 @@ -<?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 fb115f582f30..7152a6ff0880 100644 --- a/lingucomponent/source/spellcheck/languagetool/languagetoolimp.cxx +++ b/lingucomponent/source/spellcheck/languagetool/languagetoolimp.cxx @@ -56,8 +56,6 @@ 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; @@ -297,6 +295,14 @@ 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()) @@ -330,35 +336,44 @@ 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; + } - SvtLinguConfig aLinguCfg; - uno::Sequence<OUString> aLocaleList; - - if (LanguageToolCfg::RestProtocol::get().value_or("") == sDuden) + OUString localeUrl = getLocaleListURL(); + if (localeUrl.isEmpty()) { - aLocaleList.realloc(3); - aLocaleList.getArray()[0] = "de-DE"; - aLocaleList.getArray()[1] = "en-US"; - aLocaleList.getArray()[2] = "en-GB"; + return m_aSuppLocales; } - else - aLinguCfg.GetLocaleListFor("GrammarCheckers", - "org.openoffice.lingu.LanguageToolGrammarChecker", aLocaleList); + 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); - auto nLength = aLocaleList.getLength(); - m_aSuppLocales.realloc(nLength); + size_t length = root.size(); + m_aSuppLocales.realloc(length); auto pArray = m_aSuppLocales.getArray(); - auto pLocaleList = aLocaleList.getArray(); - - for (auto i = 0; i < nLength; i++) + int i = 0; + for (auto it = root.begin(); it != root.end(); it++, i++) { - pArray[i] = LanguageTag::convertToLocale(pLocaleList[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; } - return m_aSuppLocales; } |