diff options
author | Mert Tumer <mert.tumer@collabora.com> | 2022-05-10 13:06:06 +0300 |
---|---|---|
committer | Caolán McNamara <caolan.mcnamara@collabora.com> | 2023-10-22 19:02:06 +0200 |
commit | 7fbea38b7aa5335abef55b445df88ee571d18360 (patch) | |
tree | 4236a1f808badf332e59daeb000a91ee3203ec1e | |
parent | 2c0669846fe26dae2bb64308517db685037e2cf9 (diff) |
Load the locales from config file for languagetool
Locales needs to be read again
in the Preferences/Writing Aids section and since
this is a network operation it can cause a problem.
Better to list all the supported locales in the xcu
and load it right away.
Signed-off-by: Mert Tumer <mert.tumer@collabora.com>
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135598
Tested-by: Jenkins
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/153959
Reviewed-by: Andras Timar <andras.timar@collabora.com>
Tested-by: Andras Timar <andras.timar@collabora.com>
(cherry picked from commit 84bdf9e81a63a8bd308709c86b51bf3900a23c50)
Change-Id: Iad9201101aa167ad33f479c67f72649786e1f2cf
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/158330
Reviewed-by: Caolán McNamara <caolan.mcnamara@collabora.com>
-rw-r--r-- | include/unotools/lingucfg.hxx | 2 | ||||
-rw-r--r-- | lingucomponent/config/Linguistic-lingucomponent-grammarchecker.xcu | 30 | ||||
-rw-r--r-- | lingucomponent/source/spellcheck/languagetool/languagetoolimp.cxx | 51 | ||||
-rw-r--r-- | postprocess/CustomTarget_registry.mk | 1 | ||||
-rw-r--r-- | unotools/source/config/lingucfg.cxx | 21 |
5 files changed, 68 insertions, 37 deletions
diff --git a/include/unotools/lingucfg.hxx b/include/unotools/lingucfg.hxx index 40797a372f33..c924d7898764 100644 --- a/include/unotools/lingucfg.hxx +++ b/include/unotools/lingucfg.hxx @@ -196,6 +196,8 @@ public: bool GetDictionaryEntry( const OUString &rNodeName, SvtLinguConfigDictionaryEntry &rDicEntry ) const; + bool GetLocaleListFor( const OUString &rSetName, const OUString &rSetEntry, css::uno::Sequence< OUString > &rLocaleList ) const; + css::uno::Sequence< OUString > GetDisabledDictionaries() const; std::vector< SvtLinguConfigDictionaryEntry > GetActiveDictionariesByFormat( std::u16string_view rFormatName ) const; diff --git a/lingucomponent/config/Linguistic-lingucomponent-grammarchecker.xcu b/lingucomponent/config/Linguistic-lingucomponent-grammarchecker.xcu new file mode 100644 index 000000000000..6fa455d969b8 --- /dev/null +++ b/lingucomponent/config/Linguistic-lingucomponent-grammarchecker.xcu @@ -0,0 +1,30 @@ +<?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 7152a6ff0880..c4c4b6379a5f 100644 --- a/lingucomponent/source/spellcheck/languagetool/languagetoolimp.cxx +++ b/lingucomponent/source/spellcheck/languagetool/languagetoolimp.cxx @@ -295,14 +295,6 @@ 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()) @@ -336,44 +328,29 @@ 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; - } - OUString localeUrl = getLocaleListURL(); - if (localeUrl.isEmpty()) - { - return m_aSuppLocales; - } - 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); + SvtLinguConfig aLinguCfg; + uno::Sequence<OUString> aLocaleList; + aLinguCfg.GetLocaleListFor("GrammarCheckers", "org.openoffice.lingu.LanguageToolGrammarChecker", + aLocaleList); - size_t length = root.size(); - m_aSuppLocales.realloc(length); + auto nLength = aLocaleList.getLength(); + m_aSuppLocales.realloc(nLength); auto pArray = m_aSuppLocales.getArray(); - int i = 0; - for (auto it = root.begin(); it != root.end(); it++, i++) + auto pLocaleList = aLocaleList.getArray(); + + for (auto i = 0; i < nLength; 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; + pArray[i] = LanguageTag::convertToLocale(pLocaleList[i]); } + return m_aSuppLocales; } diff --git a/postprocess/CustomTarget_registry.mk b/postprocess/CustomTarget_registry.mk index b0bc7a4320f2..9e235f098b25 100644 --- a/postprocess/CustomTarget_registry.mk +++ b/postprocess/CustomTarget_registry.mk @@ -116,6 +116,7 @@ postprocess_DEPS_lingucomponent := main postprocess_FILES_lingucomponent := \ $(SRCDIR)/lingucomponent/config/Linguistic-lingucomponent-hyphenator.xcu \ $(SRCDIR)/lingucomponent/config/Linguistic-lingucomponent-spellchecker.xcu \ + $(SRCDIR)/lingucomponent/config/Linguistic-lingucomponent-grammarchecker.xcu \ $(SRCDIR)/lingucomponent/config/Linguistic-lingucomponent-thesaurus.xcu \ postprocess_FILES_main := \ diff --git a/unotools/source/config/lingucfg.cxx b/unotools/source/config/lingucfg.cxx index 571601e1663a..1a4172c7844a 100644 --- a/unotools/source/config/lingucfg.cxx +++ b/unotools/source/config/lingucfg.cxx @@ -941,6 +941,27 @@ bool SvtLinguConfig::GetSupportedDictionaryFormatsFor( return bSuccess; } +bool SvtLinguConfig::GetLocaleListFor( const OUString &rSetName, const OUString &rSetEntry, css::uno::Sequence< OUString > &rLocaleList ) const +{ + if (rSetName.isEmpty() || rSetEntry.isEmpty()) + return false; + bool bSuccess = false; + try + { + uno::Reference< container::XNameAccess > xNA( GetMainUpdateAccess(), uno::UNO_QUERY_THROW ); + xNA.set( xNA->getByName("ServiceManager"), uno::UNO_QUERY_THROW ); + xNA.set( xNA->getByName( rSetName ), uno::UNO_QUERY_THROW ); + xNA.set( xNA->getByName( rSetEntry ), uno::UNO_QUERY_THROW ); + if (xNA->getByName( "Locales" ) >>= rLocaleList) + bSuccess = true; + DBG_ASSERT( rLocaleList.hasElements(), "Locale list is empty" ); + } + catch (uno::Exception &) + { + } + return bSuccess; +} + static bool lcl_GetFileUrlFromOrigin( OUString /*out*/ &rFileUrl, const OUString &rOrigin ) |