From 382b6f118c9ce6ba94c559cfa3c521cb1a24f165 Mon Sep 17 00:00:00 2001 From: Heiko Tietze Date: Thu, 11 Jun 2026 18:22:47 +0200 Subject: [PATCH] Resolves tdf#172375 - Revert "uno:Translate with DeepL API" This reverts commit e20d2de7836da52dbf9e528d1043b1e188097bfd * DeepL is just one platform, and not open * The function requires an account * Implementation is experimental and not maintained * Better solution via extension exists * Decision to revert made at ESC on 2026/Jun/11 Change-Id: I74974671b1fbed6b3299f3532bd6f9263d65927f Reviewed-on: https://gerrit.libreoffice.org/c/core/+/206367 Reviewed-by: Heiko Tietze Tested-by: Jenkins --- cui/Library_cui.mk | 1 - cui/UIConfig_cui.mk | 1 - cui/inc/treeopt.hrc | 3 +- cui/source/options/optdeepl.cxx | 82 ------ cui/source/options/optdeepl.hxx | 41 --- cui/source/options/treeopt.cxx | 9 - cui/source/options/treeopthelper.cxx | 1 - cui/uiconfig/ui/optdeeplpage.ui | 129 --------- include/linguistic/translate.hxx | 20 -- include/sfx2/pageids.hxx | 1 - include/sfx2/sfxsids.hrc | 2 +- include/svx/svxids.hrc | 2 +- linguistic/Library_lng.mk | 1 - linguistic/source/translate.cxx | 86 ------ .../openoffice/Office/UI/WriterCommands.xcu | 8 - .../org/openoffice/Office/Linguistic.xcs | 22 -- svx/sdi/svx.sdi | 18 -- sw/Library_sw.mk | 2 +- sw/Library_swui.mk | 2 - sw/UIConfig_swriter.mk | 1 - sw/inc/strings.hrc | 1 - sw/inc/swabstdlg.hxx | 12 - sw/sdi/_textsh.sdi | 6 - sw/source/core/txtnode/atrref.cxx | 4 +- sw/source/ui/dialog/swdlgfact.cxx | 35 --- sw/source/ui/dialog/swdlgfact.hxx | 1 - sw/source/ui/misc/translatelangselect.cxx | 136 ---------- sw/source/uibase/dialog/regionsw.cxx | 4 +- sw/source/uibase/fldui/fldmgr.cxx | 4 +- .../inc/{translatehelper.hxx => pam2html.hxx} | 15 +- sw/source/uibase/inc/translatelangselect.hxx | 70 ----- sw/source/uibase/shells/basesh.cxx | 1 - sw/source/uibase/shells/pam2html.cxx | 80 ++++++ sw/source/uibase/shells/textfld.cxx | 9 +- sw/source/uibase/shells/textsh1.cxx | 48 +--- sw/source/uibase/shells/translatehelper.cxx | 250 ------------------ sw/uiconfig/sglobal/menubar/menubar.xml | 2 - sw/uiconfig/swriter/menubar/menubar.xml | 2 - sw/uiconfig/swriter/ui/translationdialog.ui | 119 --------- 39 files changed, 102 insertions(+), 1129 deletions(-) delete mode 100644 cui/source/options/optdeepl.cxx delete mode 100644 cui/source/options/optdeepl.hxx delete mode 100644 cui/uiconfig/ui/optdeeplpage.ui delete mode 100644 include/linguistic/translate.hxx delete mode 100644 linguistic/source/translate.cxx delete mode 100644 sw/source/ui/misc/translatelangselect.cxx rename sw/source/uibase/inc/{translatehelper.hxx => pam2html.hxx} (72%) delete mode 100644 sw/source/uibase/inc/translatelangselect.hxx create mode 100644 sw/source/uibase/shells/pam2html.cxx delete mode 100644 sw/source/uibase/shells/translatehelper.cxx delete mode 100644 sw/uiconfig/swriter/ui/translationdialog.ui diff --git a/cui/Library_cui.mk b/cui/Library_cui.mk index d47a25fae15f..fc6c14704c98 100644 --- a/cui/Library_cui.mk +++ b/cui/Library_cui.mk @@ -192,7 +192,6 @@ $(eval $(call gb_Library_add_exception_objects,cui,\ cui/source/options/optgenrl \ cui/source/options/opthtml \ cui/source/options/optlanguagetool \ - cui/source/options/optdeepl \ cui/source/options/optinet2 \ cui/source/options/optjava \ cui/source/options/optjsearch \ diff --git a/cui/UIConfig_cui.mk b/cui/UIConfig_cui.mk index 8b89014d42a8..fc2de02c396d 100644 --- a/cui/UIConfig_cui.mk +++ b/cui/UIConfig_cui.mk @@ -137,7 +137,6 @@ $(eval $(call gb_UIConfig_add_uifiles,cui,\ cui/uiconfig/ui/optbasicidepage \ cui/uiconfig/ui/optctlpage \ cui/uiconfig/ui/optchartcolorspage \ - cui/uiconfig/ui/optdeeplpage \ cui/uiconfig/ui/optemailpage \ cui/uiconfig/ui/optfltrpage \ cui/uiconfig/ui/optfltrembedpage \ diff --git a/cui/inc/treeopt.hrc b/cui/inc/treeopt.hrc index 48c7b06b89b6..4cd94099e4d8 100644 --- a/cui/inc/treeopt.hrc +++ b/cui/inc/treeopt.hrc @@ -54,8 +54,7 @@ const std::pair SID_LANGUAGE_OPTIONS_RES[] = { NC_("SID_LANGUAGE_OPTIONS_RES", "Searching in Japanese"), RID_SVXPAGE_JSEARCH_OPTIONS }, { NC_("SID_LANGUAGE_OPTIONS_RES", "Asian Layout"), RID_SVXPAGE_ASIAN_LAYOUT }, { NC_("SID_LANGUAGE_OPTIONS_RES", "Complex Text Layout"), RID_SVXPAGE_OPTIONS_CTL }, - { NC_("SID_LANGUAGE_OPTIONS_RES", "LanguageTool Server"), RID_SVXPAGE_LANGTOOL_OPTIONS }, - { NC_("SID_LANGUAGE_OPTIONS_RES", "DeepL Server"), RID_SVXPAGE_DEEPL_OPTIONS } + { NC_("SID_LANGUAGE_OPTIONS_RES", "LanguageTool Server"), RID_SVXPAGE_LANGTOOL_OPTIONS } }; const std::pair SID_INET_DLG_RES[] = diff --git a/cui/source/options/optdeepl.cxx b/cui/source/options/optdeepl.cxx deleted file mode 100644 index fccad1c455d5..000000000000 --- a/cui/source/options/optdeepl.cxx +++ /dev/null @@ -1,82 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * 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 . - */ - -#include "optdeepl.hxx" -#include -#include -#include -#include -#include - -OptDeeplTabPage::OptDeeplTabPage(weld::Container* pPage, weld::DialogController* pController, - const SfxItemSet& rSet) - : SfxTabPage(pPage, pController, u"cui/ui/optdeeplpage.ui"_ustr, u"OptDeeplPage"_ustr, &rSet) - , m_xAPIUrl(m_xBuilder->weld_entry(u"apiurl"_ustr)) - , m_xAuthKey(m_xBuilder->weld_entry(u"authkey"_ustr)) -{ -} - -OptDeeplTabPage::~OptDeeplTabPage() {} - -void OptDeeplTabPage::Reset(const SfxItemSet*) -{ - std::optional oDeeplAPIUrl - = officecfg::Office::Linguistic::Translation::Deepl::ApiURL::get(); - if (oDeeplAPIUrl && !oDeeplAPIUrl->isEmpty()) - m_xAPIUrl->set_text(*officecfg::Office::Linguistic::Translation::Deepl::ApiURL::get()); - - std::optional oDeeplAuthKey - = officecfg::Office::Linguistic::Translation::Deepl::AuthKey::get(); - if (oDeeplAuthKey && !oDeeplAuthKey->isEmpty()) - m_xAuthKey->set_text(*officecfg::Office::Linguistic::Translation::Deepl::AuthKey::get()); -} - -OUString OptDeeplTabPage::GetAllStrings() -{ - OUStringBuffer sAllStrings; - OUString labels[] = { u"label1"_ustr, u"label2"_ustr, u"label3"_ustr }; - - for (const auto& label : labels) - { - if (const auto pString = m_xBuilder->weld_label(label)) - sAllStrings.append(pString->get_label() + " "); - } - - if (const auto pString = m_xBuilder->weld_link_button(u"privacy"_ustr)) - sAllStrings.append(pString->get_label() + " "); - - return sAllStrings.toString().replaceAll("_", ""); -} - -bool OptDeeplTabPage::FillItemSet(SfxItemSet*) -{ - std::shared_ptr batch( - comphelper::ConfigurationChanges::create()); - officecfg::Office::Linguistic::Translation::Deepl::ApiURL::set(m_xAPIUrl->get_text(), batch); - officecfg::Office::Linguistic::Translation::Deepl::AuthKey::set(m_xAuthKey->get_text(), batch); - batch->commit(); - return false; -} - -std::unique_ptr OptDeeplTabPage::Create(weld::Container* pPage, - weld::DialogController* pController, - const SfxItemSet* rAttrSet) -{ - return std::make_unique(pPage, pController, *rAttrSet); -} diff --git a/cui/source/options/optdeepl.hxx b/cui/source/options/optdeepl.hxx deleted file mode 100644 index 00f570e1dcd7..000000000000 --- a/cui/source/options/optdeepl.hxx +++ /dev/null @@ -1,41 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * 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 . - */ -#pragma once - -#include -#include - -class OptDeeplTabPage : public SfxTabPage -{ -public: - OptDeeplTabPage(weld::Container* pPage, weld::DialogController* pController, - const SfxItemSet& rSet); - virtual ~OptDeeplTabPage() override; - static std::unique_ptr - Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rAttrSet); - - virtual OUString GetAllStrings() override; - - virtual bool FillItemSet(SfxItemSet* rSet) override; - virtual void Reset(const SfxItemSet* rSet) override; - -private: - std::unique_ptr m_xAPIUrl; - std::unique_ptr m_xAuthKey; -}; diff --git a/cui/source/options/treeopt.cxx b/cui/source/options/treeopt.cxx index 5b638a68c7c3..aec84eb83bbc 100644 --- a/cui/source/options/treeopt.cxx +++ b/cui/source/options/treeopt.cxx @@ -60,7 +60,6 @@ #include #include "optbasic.hxx" #include "optlanguagetool.hxx" -#include "optdeepl.hxx" // include search util #include @@ -270,7 +269,6 @@ static std::unique_ptr CreateGeneralTabPage(sal_uInt16 nId, weld::Co case RID_SVXPAGE_ACCESSIBILITYCONFIG: fnCreate = &SvxAccessibilityOptionsTabPage::Create; break; case RID_SVXPAGE_OPTIONS_CTL: fnCreate = &SvxCTLOptionsPage::Create ; break; case RID_SVXPAGE_LANGTOOL_OPTIONS: fnCreate = &OptLanguageToolTabPage::Create ; break; - case RID_SVXPAGE_DEEPL_OPTIONS: fnCreate = &OptDeeplTabPage::Create ; break; case RID_SVXPAGE_OPTIONS_JAVA: fnCreate = &SvxJavaOptionsPage::Create ; break; case RID_SVXPAGE_ONLINEUPDATE: fnCreate = &SvxOnlineUpdateTabPage::Create; break; case RID_OPTPAGE_CHART_DEFCOLORS: fnCreate = &SvxDefaultColorOptPage::Create; break; @@ -1775,13 +1773,6 @@ void OfaTreeOptionsDialog::languageOptions(const std::vector& vPageI if ( lcl_isOptionHidden( nPageId, aOptionsDlgOpt ) ) continue; - // Disable DeepL translation settings, if experimental mode is not enabled - if( RID_SVXPAGE_DEEPL_OPTIONS == nPageId ) - { - if( ! officecfg::Office::Common::Misc::ExperimentalMode::get() ) - continue; - } - if ( ( RID_SVXPAGE_JSEARCH_OPTIONS != nPageId || SvtCJKOptions::IsJapaneseFindEnabled() ) && ( RID_SVXPAGE_ASIAN_LAYOUT != nPageId || SvtCJKOptions::IsAsianTypographyEnabled() ) && ( RID_SVXPAGE_OPTIONS_CTL != nPageId || SvtCTLOptions::IsCTLFontEnabled() ) ) diff --git a/cui/source/options/treeopthelper.cxx b/cui/source/options/treeopthelper.cxx index e7f9a173ae6d..04254b702647 100644 --- a/cui/source/options/treeopthelper.cxx +++ b/cui/source/options/treeopthelper.cxx @@ -64,7 +64,6 @@ static PageIdToFileNameMap_Impl FileMap_Impl[] = { { RID_SVXPAGE_ASIAN_LAYOUT, u""_ustr }, // AsianLayout { RID_SVXPAGE_OPTIONS_CTL, u""_ustr }, // ComplexTextLayout { RID_SVXPAGE_LANGTOOL_OPTIONS, u""_ustr }, // LanguageTool Server - { RID_SVXPAGE_DEEPL_OPTIONS, u""_ustr }, // DeepL Server // Internet, SID_INET_DLG { RID_SVXPAGE_INET_PROXY, u""_ustr }, // Proxy diff --git a/cui/uiconfig/ui/optdeeplpage.ui b/cui/uiconfig/ui/optdeeplpage.ui deleted file mode 100644 index b7c8e9aba82b..000000000000 --- a/cui/uiconfig/ui/optdeeplpage.ui +++ /dev/null @@ -1,129 +0,0 @@ - - - - - - True - False - True - True - 6 - vertical - - - True - False - 0 - none - - - - True - False - 12 - 6 - 6 - 12 - - - Please read the privacy policy - True - True - True - start - none - https://www.deepl.com/privacy/ - - - 0 - 0 - - - - - - True - False - 6 - 12 - - - True - False - start - API URL: - True - apiurl - - - 0 - 0 - - - - - True - False - start - Authentication key: - True - authkey - - - 0 - 1 - - - - - True - True - True - True - - - 1 - 0 - - - - - True - True - True - True - - - 1 - 1 - - - - - 0 - 1 - - - - - - - True - False - DeepL API Options - True - grid1 - - - - - - - - False - True - 1 - - - - diff --git a/include/linguistic/translate.hxx b/include/linguistic/translate.hxx deleted file mode 100644 index 0d5643f056c1..000000000000 --- a/include/linguistic/translate.hxx +++ /dev/null @@ -1,20 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ -/* - * 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/. - */ - -#pragma once -#include -#include - -namespace linguistic -{ -LNG_DLLPUBLIC OString Translate(const OString& rTargetLang, const OString& rAPIUrl, - const OString& rAuthKey, const OString& rData); -} // namespace - -/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/include/sfx2/pageids.hxx b/include/sfx2/pageids.hxx index 97b9df8d868a..0fc1966db397 100644 --- a/include/sfx2/pageids.hxx +++ b/include/sfx2/pageids.hxx @@ -56,7 +56,6 @@ #define RID_SVXPAGE_APPEARANCE (RID_SVX_START + 247) #define RID_SVXPAGE_BASICIDE_OPTIONS (RID_SVX_START + 209) #define RID_SVXPAGE_LANGTOOL_OPTIONS (RID_SVX_START + 210) -#define RID_SVXPAGE_DEEPL_OPTIONS (RID_SVX_START + 211) // Resource-Id's ------------------------------------------------------------ diff --git a/include/sfx2/sfxsids.hrc b/include/sfx2/sfxsids.hrc index 0cca69e3b251..4619330b215a 100644 --- a/include/sfx2/sfxsids.hrc +++ b/include/sfx2/sfxsids.hrc @@ -224,7 +224,7 @@ class SvxZoomItem; #define SID_VIEW_DATA_SOURCE_BROWSER TypedWhichId(SID_SFX_START + 1660) #define SID_UNPACK TypedWhichId(SID_SFX_START + 1662) // (SID_SFX_START + 1663) used further down -#define SID_ATTR_TARGETLANG_STR (SID_SFX_START + 1664) +// (SID_SFX_START + 1664) was SID_ATTR_TARGETLANG_STR introduced with e20d2de7836da52dbf9e528d1043b1e188097bfd #define SID_GO_TO_PAGE (SID_SFX_START + 1665) #define SID_OUTPUTSTREAM TypedWhichId(SID_SFX_START + 1666) #define SID_IMAGE_ORIENTATION TypedWhichId(SID_SFX_START + 1667) diff --git a/include/svx/svxids.hrc b/include/svx/svxids.hrc index 1db3d1a434a5..551443801d86 100644 --- a/include/svx/svxids.hrc +++ b/include/svx/svxids.hrc @@ -604,7 +604,7 @@ class XFillGradientItem; #define SID_FM_FILECONTROL ( SID_SVX_START + 605 ) //( SID_SVX_START + 606 ) is used by SID_DRAWTBX_REDACTED_EXPORT #define SID_FM_NAVIGATIONBAR ( SID_SVX_START + 607 ) -#define SID_FM_TRANSLATE ( SID_SVX_START + 608 ) +// was SID_FM_TRANSLATE introduced with e20d2de7836da52dbf9e528d1043b1e188097bfd //FREE #define SID_FM_DELETEROWS ( SID_SVX_START + 610 ) //FREE diff --git a/linguistic/Library_lng.mk b/linguistic/Library_lng.mk index 4991163ed070..2cc4e317067c 100644 --- a/linguistic/Library_lng.mk +++ b/linguistic/Library_lng.mk @@ -77,7 +77,6 @@ $(eval $(call gb_Library_add_exception_objects,lng,\ linguistic/source/spelldsp \ linguistic/source/spelldta \ linguistic/source/thesdsp \ - $(if $(ENABLE_CURL),linguistic/source/translate) \ )) # vim: set noet sw=4 ts=4: diff --git a/linguistic/source/translate.cxx b/linguistic/source/translate.cxx deleted file mode 100644 index acc811e63f2d..000000000000 --- a/linguistic/source/translate.cxx +++ /dev/null @@ -1,86 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ -/* - * 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/. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace linguistic -{ -OString Translate(const OString& rTargetLang, const OString& rAPIUrl, const OString& rAuthKey, - const OString& rData) -{ - constexpr tools::Long CURL_TIMEOUT = 10L; - - std::unique_ptr> curl(curl_easy_init(), - [](CURL* p) { curl_easy_cleanup(p); }); - - ::InitCurl_easy(curl.get()); - - (void)curl_easy_setopt(curl.get(), CURLOPT_URL, rAPIUrl.getStr()); - (void)curl_easy_setopt(curl.get(), CURLOPT_FAILONERROR, 1L); - (void)curl_easy_setopt(curl.get(), CURLOPT_TIMEOUT, CURL_TIMEOUT); - - std::string response_body; - (void)curl_easy_setopt(curl.get(), CURLOPT_WRITEFUNCTION, - +[](void* buffer, size_t size, size_t nmemb, void* userp) -> size_t { - if (!userp) - return 0; - std::string* response = static_cast(userp); - size_t real_size = size * nmemb; - response->append(static_cast(buffer), real_size); - return real_size; - }); - (void)curl_easy_setopt(curl.get(), CURLOPT_WRITEDATA, static_cast(&response_body)); - OString aLang(curl_easy_escape(curl.get(), rTargetLang.getStr(), rTargetLang.getLength())); - OString aAuthKey(curl_easy_escape(curl.get(), rAuthKey.getStr(), rAuthKey.getLength())); - OString aData(curl_easy_escape(curl.get(), rData.getStr(), rData.getLength())); - OString aPostData("auth_key=" + aAuthKey + "&target_lang=" + aLang + "&text=" + aData); - - (void)curl_easy_setopt(curl.get(), CURLOPT_POSTFIELDS, aPostData.getStr()); - CURLcode cc = curl_easy_perform(curl.get()); - if (cc != CURLE_OK) - { - SAL_WARN("linguistic", - "Translate: CURL perform returned with error: " << static_cast(cc)); - return {}; - } - tools::Long nStatusCode; - curl_easy_getinfo(curl.get(), CURLINFO_RESPONSE_CODE, &nStatusCode); - if (nStatusCode != 200) - { - SAL_WARN("linguistic", - "Translate: CURL request returned with status code: " << nStatusCode); - return {}; - } - // parse the response - boost::property_tree::ptree root; - std::stringstream aStream(response_body.data()); - boost::property_tree::read_json(aStream, root); - boost::property_tree::ptree& translations = root.get_child("translations"); - size_t size = translations.size(); - if (size <= 0) - { - SAL_WARN("linguistic", "Translate: API did not return any translations"); - return {}; - } - // take the first one - const boost::property_tree::ptree& translation = translations.begin()->second; - const std::string text = translation.get("text"); - return OString(text); -} -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/officecfg/registry/data/org/openoffice/Office/UI/WriterCommands.xcu b/officecfg/registry/data/org/openoffice/Office/UI/WriterCommands.xcu index d655db6fbc6b..a8fa67331673 100644 --- a/officecfg/registry/data/org/openoffice/Office/UI/WriterCommands.xcu +++ b/officecfg/registry/data/org/openoffice/Office/UI/WriterCommands.xcu @@ -1584,14 +1584,6 @@ 1 - - - Translate... - - - 1 - - Co~lumns... diff --git a/officecfg/registry/schema/org/openoffice/Office/Linguistic.xcs b/officecfg/registry/schema/org/openoffice/Office/Linguistic.xcs index 8fcb6a3ccd62..1da9958f5763 100644 --- a/officecfg/registry/schema/org/openoffice/Office/Linguistic.xcs +++ b/officecfg/registry/schema/org/openoffice/Office/Linguistic.xcs @@ -415,28 +415,6 @@ - - - Contains translation relevant settings. - - - - Contains DeepL API relevant settings. - - - - Deepl Translator API URL - - - - - - Deepl Translator API URL Authkey - - - - - Contains hyphenation relevant settings. diff --git a/svx/sdi/svx.sdi b/svx/sdi/svx.sdi index c599bfb52e01..4eeccdcb6f2c 100644 --- a/svx/sdi/svx.sdi +++ b/svx/sdi/svx.sdi @@ -1642,24 +1642,6 @@ SfxBoolItem NavigationBar SID_FM_NAVIGATIONBAR GroupId = SfxGroupId::Controls; ] -SfxBoolItem Translate SID_FM_TRANSLATE -(SfxStringItem TargetLang SID_ATTR_TARGETLANG_STR) -[ - AutoUpdate = FALSE, - FastCall = TRUE, - ReadOnlyDoc = FALSE, - Toggle = FALSE, - Container = FALSE, - RecordAbsolute = FALSE, - RecordPerSet; - - AccelConfig = FALSE, - MenuConfig = FALSE, - ToolBoxConfig = FALSE, - GroupId = SfxGroupId::Format; -] - - SfxBoolItem Combobox SID_INSERT_COMBOBOX [ diff --git a/sw/Library_sw.mk b/sw/Library_sw.mk index 42e26a455ddd..aa41dbd01160 100644 --- a/sw/Library_sw.mk +++ b/sw/Library_sw.mk @@ -715,7 +715,7 @@ $(eval $(call gb_Library_add_exception_objects,sw,\ sw/source/uibase/shells/grfsh \ sw/source/uibase/shells/grfshex \ sw/source/uibase/shells/langhelper \ - sw/source/uibase/shells/translatehelper \ + sw/source/uibase/shells/pam2html \ sw/source/uibase/shells/listsh \ sw/source/uibase/shells/mediash \ sw/source/uibase/shells/navsh \ diff --git a/sw/Library_swui.mk b/sw/Library_swui.mk index 3642ec7292fe..ce5ba5b1bf3f 100644 --- a/sw/Library_swui.mk +++ b/sw/Library_swui.mk @@ -80,7 +80,6 @@ $(eval $(call gb_Library_use_libraries,swui,\ vcl \ drawinglayercore \ drawinglayer \ - lng \ )) $(eval $(call gb_Library_add_exception_objects,swui,\ @@ -156,7 +155,6 @@ $(eval $(call gb_Library_add_exception_objects,swui,\ sw/source/ui/misc/pgfnote \ sw/source/ui/misc/pggrid \ sw/source/ui/misc/srtdlg \ - $(if $(ENABLE_CURL),sw/source/ui/misc/translatelangselect) \ sw/source/ui/misc/swmodalredlineacceptdlg \ sw/source/ui/misc/titlepage \ sw/source/ui/table/colwd \ diff --git a/sw/UIConfig_swriter.mk b/sw/UIConfig_swriter.mk index 972fcc70c676..321641bd9899 100644 --- a/sw/UIConfig_swriter.mk +++ b/sw/UIConfig_swriter.mk @@ -190,7 +190,6 @@ $(eval $(call gb_UIConfig_add_uifiles,modules/swriter,\ sw/uiconfig/swriter/ui/insertautotextdialog \ sw/uiconfig/swriter/ui/insertbookmark \ sw/uiconfig/swriter/ui/insertbreak \ - sw/uiconfig/swriter/ui/translationdialog \ sw/uiconfig/swriter/ui/insertcaption \ sw/uiconfig/swriter/ui/insertdbcolumnsdialog \ sw/uiconfig/swriter/ui/insertfootnote \ diff --git a/sw/inc/strings.hrc b/sw/inc/strings.hrc index 8fd528d354fe..4bd7e6f0be85 100644 --- a/sw/inc/strings.hrc +++ b/sw/inc/strings.hrc @@ -300,7 +300,6 @@ #define STR_DELETE_NOTE_AUTHOR NC_("STR_DELETE_NOTE_AUTHOR", "Delete ~All Comments by $1") #define STR_HIDE_NOTE_AUTHOR NC_("STR_HIDE_NOTE_AUTHOR", "H~ide All Comments by $1") #define STR_OUTLINE_NUMBERING NC_("STR_OUTLINE_NUMBERING", "Heading Numbering") -#define STR_STATSTR_SWTRANSLATE NC_("STR_STATSTR_SWTRANSLATE", "Translating document...") #define STR_SWTRANSLATE_ERROR NC_("STR_SWTRANSLATE_ERROR", "Error translating document.") /* To translators: $1 == will be replaced by STR_WORDCOUNT_WORDARG, and $2 by STR_WORDCOUNT_COLARG e.g. Selected: 1 word, 2 characters */ diff --git a/sw/inc/swabstdlg.hxx b/sw/inc/swabstdlg.hxx index 3330d34a7f04..cff86c1cfd7d 100644 --- a/sw/inc/swabstdlg.hxx +++ b/sw/inc/swabstdlg.hxx @@ -412,17 +412,6 @@ public: virtual sal_uInt16 GetRestartPage() const = 0; }; -class SwLanguageListItem; - -class AbstractSwTranslateLangSelectDlg -{ -protected: - virtual ~AbstractSwTranslateLangSelectDlg() = default; -public: - virtual std::shared_ptr getDialogController() = 0; - virtual std::optional GetSelectedLanguage() = 0; -}; - class AbstractSwSortDlg : public VclAbstractDialog { protected: @@ -494,7 +483,6 @@ public: CreateSwContentControlListItemDlg(weld::Window* pParent, SwContentControlListItem& rItem) = 0; virtual std::shared_ptr CreateSwBreakDlg(weld::Window *pParent, SwWrtShell &rSh) = 0; - virtual std::shared_ptr CreateSwTranslateLangSelectDlg(weld::Window *pParent, SwWrtShell &rSh) = 0; virtual VclPtr CreateSwChangeDBDlg(SwView& rVw) = 0; virtual VclPtr CreateSwCharDlg(weld::Window* pParent, SwView& rView, const SfxItemSet& rCoreSet, SwCharDlgMode nDialogMode, const OUString* pFormatStr = nullptr) = 0; diff --git a/sw/sdi/_textsh.sdi b/sw/sdi/_textsh.sdi index c74f30430ea3..f0218d8b9512 100644 --- a/sw/sdi/_textsh.sdi +++ b/sw/sdi/_textsh.sdi @@ -1971,11 +1971,5 @@ FN_INSERT_LANDSCAPE_PAGE // status(final|play) StateMethod = GetState ; ] - SID_FM_TRANSLATE - [ - ExecMethod = Execute ; - StateMethod = GetState ; - ] - } // end of interface text diff --git a/sw/source/core/txtnode/atrref.cxx b/sw/source/core/txtnode/atrref.cxx index 6230fe40b136..91fffcfd499a 100644 --- a/sw/source/core/txtnode/atrref.cxx +++ b/sw/source/core/txtnode/atrref.cxx @@ -33,7 +33,7 @@ #include #include #include -#include +#include #include SwFormatRefMark::~SwFormatRefMark( ) @@ -187,7 +187,7 @@ void SwTextRefMark::UpdateFieldContent(SwDoc* pDoc, SwWrtShell& rWrtSh, const OU // Paste HTML content. SwPaM* pCursorPos = rWrtSh.GetCursor(); *pCursorPos = aPasteEnd; - SwTranslateHelper::PasteHTMLToPaM(rWrtSh, pCursorPos, aContent.toUtf8()); + SwPam2Html::PasteHTMLToPaM(rWrtSh, pCursorPos, aContent.toUtf8()); // Update the refmark to point to the new content. sal_Int32 nOldStart = this->GetStart(); diff --git a/sw/source/ui/dialog/swdlgfact.cxx b/sw/source/ui/dialog/swdlgfact.cxx index 3329399de2b7..265c8837c466 100644 --- a/sw/source/ui/dialog/swdlgfact.cxx +++ b/sw/source/ui/dialog/swdlgfact.cxx @@ -91,7 +91,6 @@ #include #include #include -#include #include #include #include @@ -131,20 +130,6 @@ public: std::shared_ptr getDialogController() override { return m_xDlg; } }; -class AbstractSwTranslateLangSelectDlg_Impl : public AbstractSwTranslateLangSelectDlg -{ - std::shared_ptr m_xDlg; - -public: - explicit AbstractSwTranslateLangSelectDlg_Impl(std::shared_ptr p) - : m_xDlg(std::move(p)) - { - } - - std::shared_ptr getDialogController() override { return m_xDlg; } - std::optional GetSelectedLanguage() override; -}; - class AbstractInsTableDlg_Impl : public AbstractInsTableDlg { std::shared_ptr m_xDlg; @@ -206,15 +191,6 @@ void AbstractInsTableDlg_Impl::GetValues( OUString& rName, sal_uInt16& rRow, sal pDlg->GetValues(rName, rRow, rCol, rInsTableFlags, rTableAutoFormatName, prTAFormat); } -std::optional AbstractSwTranslateLangSelectDlg_Impl::GetSelectedLanguage() -{ -#if HAVE_FEATURE_CURL && !ENABLE_WASM_STRIP_EXTRA - return SwTranslateLangSelectDlg::GetSelectedLanguage(); -#else - return {}; -#endif -} - namespace { class AbstractSwInsertAbstractDlg_Impl @@ -329,17 +305,6 @@ std::shared_ptr SwAbstractDialogFactory_Impl::CreateSwBreakD return std::make_shared(std::make_unique(pParent, rSh)); } -std::shared_ptr SwAbstractDialogFactory_Impl::CreateSwTranslateLangSelectDlg(weld::Window* pParent, SwWrtShell &rSh) -{ -#if HAVE_FEATURE_CURL && !ENABLE_WASM_STRIP_EXTRA - return std::make_shared(std::make_unique(pParent, rSh)); -#else - (void) pParent; - (void) rSh; - return nullptr; -#endif -} - namespace { class AbstractChangeDbDialog_Impl diff --git a/sw/source/ui/dialog/swdlgfact.hxx b/sw/source/ui/dialog/swdlgfact.hxx index 3d6956dbb1f4..3536db5dc885 100644 --- a/sw/source/ui/dialog/swdlgfact.hxx +++ b/sw/source/ui/dialog/swdlgfact.hxx @@ -83,7 +83,6 @@ public: SwContentControlListItem& rItem) override; virtual std::shared_ptr CreateSwBreakDlg(weld::Window *pParent, SwWrtShell &rSh) override; - virtual std::shared_ptr CreateSwTranslateLangSelectDlg(weld::Window *pParent, SwWrtShell &rSh) override; virtual VclPtr CreateSwChangeDBDlg(SwView& rVw) override; virtual VclPtr CreateSwCharDlg(weld::Window* pParent, SwView& pVw, const SfxItemSet& rCoreSet, SwCharDlgMode nDialogMode, const OUString* pFormatStr = nullptr) override; diff --git a/sw/source/ui/misc/translatelangselect.cxx b/sw/source/ui/misc/translatelangselect.cxx deleted file mode 100644 index 805c1d8aa9aa..000000000000 --- a/sw/source/ui/misc/translatelangselect.cxx +++ /dev/null @@ -1,136 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * 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 . - */ - -#include - -#include -#include -#include -#include -#include -#include -#include - -static const std::vector& getLanguageVec() -{ - static const std::vector gLanguageVec{ - SwLanguageListItem("BG"_ostr, "Bulgarian"_ostr), - SwLanguageListItem("CS"_ostr, "Czech"_ostr), - SwLanguageListItem("DA"_ostr, "Danish"_ostr), - SwLanguageListItem("DE"_ostr, "German"_ostr), - SwLanguageListItem("EL"_ostr, "Greek"_ostr), - SwLanguageListItem("EN-GB"_ostr, "English (British)"_ostr), - SwLanguageListItem("EN-US"_ostr, "English (American)"_ostr), - SwLanguageListItem("ES"_ostr, "Spanish"_ostr), - SwLanguageListItem("ET"_ostr, "Estonian"_ostr), - SwLanguageListItem("FI"_ostr, "Finnish"_ostr), - SwLanguageListItem("FR"_ostr, "French"_ostr), - SwLanguageListItem("HU"_ostr, "Hungarian"_ostr), - SwLanguageListItem("ID"_ostr, "Indonesian"_ostr), - SwLanguageListItem("IT"_ostr, "Italian"_ostr), - SwLanguageListItem("JA"_ostr, "Japanese"_ostr), - SwLanguageListItem("LT"_ostr, "Lithuanian"_ostr), - SwLanguageListItem("LV"_ostr, "Latvian"_ostr), - SwLanguageListItem("NL"_ostr, "Dutch"_ostr), - SwLanguageListItem("PL"_ostr, "Polish"_ostr), - SwLanguageListItem("PT-BR"_ostr, "Portuguese (Brazilian)"_ostr), - SwLanguageListItem("PT-PT"_ostr, "Portuguese (European)"_ostr), - SwLanguageListItem("RO"_ostr, "Romanian"_ostr), - SwLanguageListItem("RU"_ostr, "Russian"_ostr), - SwLanguageListItem("SK"_ostr, "Slovak"_ostr), - SwLanguageListItem("SL"_ostr, "Slovenian"_ostr), - SwLanguageListItem("SV"_ostr, "Swedish"_ostr), - SwLanguageListItem("TR"_ostr, "Turkish"_ostr), - SwLanguageListItem("ZH"_ostr, "Chinese (simplified)"_ostr) - }; - return gLanguageVec; -} - -int SwTranslateLangSelectDlg::selectedLangIdx = -1; -SwTranslateLangSelectDlg::SwTranslateLangSelectDlg(weld::Window* pParent, SwWrtShell& rSh) - : GenericDialogController(pParent, u"modules/swriter/ui/translationdialog.ui"_ustr, - u"LanguageSelectDialog"_ustr) - , m_rWrtSh(rSh) - , m_xLanguageListBox(m_xBuilder->weld_combo_box(u"combobox1"_ustr)) - , m_xBtnCancel(m_xBuilder->weld_button(u"cancel"_ustr)) - , m_xBtnTranslate(m_xBuilder->weld_button(u"translate"_ustr)) - , m_bTranslationStarted(false) - , m_bCancelTranslation(false) -{ - m_xLanguageListBox->connect_changed(LINK(this, SwTranslateLangSelectDlg, LangSelectHdl)); - m_xBtnCancel->connect_clicked(LINK(this, SwTranslateLangSelectDlg, LangSelectCancelHdl)); - m_xBtnTranslate->connect_clicked(LINK(this, SwTranslateLangSelectDlg, LangSelectTranslateHdl)); - - for (const auto& item : getLanguageVec()) - { - m_xLanguageListBox->append_text(OStringToOUString(item.getName(), RTL_TEXTENCODING_UTF8)); - } - - if (SwTranslateLangSelectDlg::selectedLangIdx != -1) - { - m_xLanguageListBox->set_active(SwTranslateLangSelectDlg::selectedLangIdx); - } -} - -std::optional SwTranslateLangSelectDlg::GetSelectedLanguage() -{ - if (SwTranslateLangSelectDlg::selectedLangIdx != -1) - { - return getLanguageVec().at(SwTranslateLangSelectDlg::selectedLangIdx); - } - - return {}; -} - -IMPL_STATIC_LINK(SwTranslateLangSelectDlg, LangSelectHdl, weld::ComboBox&, rBox, void) -{ - const auto selected = rBox.get_active(); - SwTranslateLangSelectDlg::selectedLangIdx = selected; -} - -IMPL_LINK_NOARG(SwTranslateLangSelectDlg, LangSelectCancelHdl, weld::Button&, void) -{ - // stop translation first - if (m_bTranslationStarted) - m_bCancelTranslation = true; - else - m_xDialog->response(RET_CANCEL); -} - -IMPL_LINK_NOARG(SwTranslateLangSelectDlg, LangSelectTranslateHdl, weld::Button&, void) -{ - if (m_bTranslationStarted) - return; - if (SwTranslateLangSelectDlg::selectedLangIdx == -1) - { - m_xDialog->response(RET_CANCEL); - return; - } - - const auto aTargetLang - = getLanguageVec().at(SwTranslateLangSelectDlg::selectedLangIdx).getLanguage(); - - m_bTranslationStarted = true; - m_xBtnTranslate->set_sensitive(false); - bool bRet = SwTranslateHelper::TranslateDocumentCancellable(m_rWrtSh, aTargetLang, - m_bCancelTranslation); - m_xDialog->response(bRet ? RET_OK : RET_CANCEL); -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/uibase/dialog/regionsw.cxx b/sw/source/uibase/dialog/regionsw.cxx index f10b6c164d54..f1b06b32b9e0 100644 --- a/sw/source/uibase/dialog/regionsw.cxx +++ b/sw/source/uibase/dialog/regionsw.cxx @@ -33,8 +33,8 @@ #include #include #include -#include #include +#include void SwBaseShell::InsertRegionDialog(SfxRequest& rReq) { @@ -160,7 +160,7 @@ void SwBaseShell::InsertRegionDialog(SfxRequest& rReq) SwPaM* pCursorPos = rSh.GetCursor(); pCursorPos->Move(fnMoveBackward, GoInContent); // Paste HTML content. - SwTranslateHelper::PasteHTMLToPaM(rSh, pCursorPos, aSectionContent.toUtf8()); + SwPam2Html::PasteHTMLToPaM(rSh, pCursorPos, aSectionContent.toUtf8()); if (pCursorPos->GetPoint()->GetContentIndex() == 0) { // The paste created a last empty text node, remove it. diff --git a/sw/source/uibase/fldui/fldmgr.cxx b/sw/source/uibase/fldui/fldmgr.cxx index bab2bec913ce..5a65c0d79152 100644 --- a/sw/source/uibase/fldui/fldmgr.cxx +++ b/sw/source/uibase/fldui/fldmgr.cxx @@ -74,13 +74,13 @@ #include #include #include +#include #include #include #if ENABLE_YRS #include #include #endif -#include #include using namespace com::sun::star::uno; @@ -1091,7 +1091,7 @@ bool SwFieldMgr::InsertField( aRefmarkPam.Move(fnMoveBackward, GoInContent); // Paste HTML content. - SwTranslateHelper::PasteHTMLToPaM( + SwPam2Html::PasteHTMLToPaM( *pCurShell, pCursorPos, rRefmarkText.toUtf8()); // Undo the above SplitNode(). diff --git a/sw/source/uibase/inc/translatehelper.hxx b/sw/source/uibase/inc/pam2html.hxx similarity index 72% rename from sw/source/uibase/inc/translatehelper.hxx rename to sw/source/uibase/inc/pam2html.hxx index 2fd45b733d2d..ddf7155de6c2 100644 --- a/sw/source/uibase/inc/translatehelper.hxx +++ b/sw/source/uibase/inc/pam2html.hxx @@ -22,21 +22,12 @@ #include -#include - #include -class SwWrtShell; -class SwPaM; - -namespace SwTranslateHelper +namespace SwPam2Html { SW_DLLPUBLIC OString ExportPaMToHTML(SwPaM* pCursor); SW_DLLPUBLIC void PasteHTMLToPaM(SwWrtShell& rWrtSh, const SwPaM* pCursor, const OString& rData); -#if HAVE_FEATURE_CURL -SW_DLLPUBLIC void TranslateDocument(SwWrtShell& rWrtSh, const OString& rTargetLang); -SW_DLLPUBLIC bool TranslateDocumentCancellable(SwWrtShell& rWrtSh, const OString& rTargetLang, - const bool& rCancelTranslation); -SW_DLLPUBLIC bool IsTranslationServiceConfigured(); -#endif } + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/uibase/inc/translatelangselect.hxx b/sw/source/uibase/inc/translatelangselect.hxx deleted file mode 100644 index 22009621d073..000000000000 --- a/sw/source/uibase/inc/translatelangselect.hxx +++ /dev/null @@ -1,70 +0,0 @@ - -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * 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 . - */ -#pragma once - -#include -#include -#include -#include -#include -#include - -class SwWrtShell; - -// SwLanguageListItem Helper class for displaying available languages with their names and tags on the listbox. -class SwLanguageListItem final -{ -public: - SwLanguageListItem(const OString& sLanguage, const OString& sName) - : m_sLanguage(sLanguage) - , m_sName(sName) - { - } - const OString& getLanguage() const { return m_sLanguage; } - const OString& getName() const { return m_sName; } - -private: - const OString m_sLanguage; - const OString m_sName; -}; - -// SwTranslateLangSelectDlg Language selection dialog for translation API. -class SwTranslateLangSelectDlg final : public weld::GenericDialogController -{ -public: - static int selectedLangIdx; - SwTranslateLangSelectDlg(weld::Window* pParent, SwWrtShell& rSh); - static std::optional GetSelectedLanguage(); - -private: - SwWrtShell& m_rWrtSh; - std::unique_ptr m_xLanguageListBox; - std::unique_ptr m_xBtnCancel; - std::unique_ptr m_xBtnTranslate; - - bool m_bTranslationStarted; - bool m_bCancelTranslation; - - DECL_STATIC_LINK(SwTranslateLangSelectDlg, LangSelectHdl, weld::ComboBox&, void); - DECL_LINK(LangSelectCancelHdl, weld::Button&, void); - DECL_LINK(LangSelectTranslateHdl, weld::Button&, void); -}; - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/uibase/shells/basesh.cxx b/sw/source/uibase/shells/basesh.cxx index f088ceef3933..e848fb925857 100644 --- a/sw/source/uibase/shells/basesh.cxx +++ b/sw/source/uibase/shells/basesh.cxx @@ -121,7 +121,6 @@ #include #include #include -#include #include FlyMode SwBaseShell::s_eFrameMode = FLY_DRAG_END; diff --git a/sw/source/uibase/shells/pam2html.cxx b/sw/source/uibase/shells/pam2html.cxx new file mode 100644 index 000000000000..29404f636023 --- /dev/null +++ b/sw/source/uibase/shells/pam2html.cxx @@ -0,0 +1,80 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 . + */ + +#include + +#include +#include +#include +#include +#include +#include + +namespace SwPam2Html +{ +OString ExportPaMToHTML(SwPaM* pCursor) +{ + SolarMutexGuard gMutex; + OString aResult; + WriterRef xWrt; + GetHTMLWriter(u"NoLineLimit,SkipHeaderFooter,NoPrettyPrint", OUString(), xWrt); + if (pCursor != nullptr) + { + SvMemoryStream aMemoryStream; + SwWriter aWriter(aMemoryStream, *pCursor); + ErrCodeMsg nError = aWriter.Write(xWrt); + if (nError.IsError()) + { + SAL_WARN("sw.ui", "ExportPaMToHTML: failed to export selection to HTML " << nError); + return {}; + } + aResult + = OString(static_cast(aMemoryStream.GetData()), aMemoryStream.GetSize()); + aResult = aResult.replaceAll(""_ostr, ""_ostr); + + // HTML has for that
and

also does new line + aResult = aResult.replaceAll("

    "_ostr, ""_ostr); + aResult = aResult.replaceAll("
"_ostr, ""_ostr); + aResult = aResult.replaceAll("
    "_ostr, ""_ostr); + aResult = aResult.replaceAll("
"_ostr, ""_ostr); + aResult = aResult.replaceAll("\n"_ostr, ""_ostr).trim(); + return aResult; + } + return {}; +} + +void PasteHTMLToPaM(SwWrtShell& rWrtSh, const SwPaM* pCursor, const OString& rData) +{ + SolarMutexGuard gMutex; + rtl::Reference pHtmlTransferable + = new vcl::unohelper::HtmlTransferable(rData); + if (pHtmlTransferable.is()) + { + TransferableDataHelper aDataHelper(pHtmlTransferable); + if (aDataHelper.GetXTransferable().is() + && SwTransferable::IsPasteSpecial(rWrtSh, aDataHelper)) + { + rWrtSh.SetSelection(*pCursor); + SwTransferable::Paste(rWrtSh, aDataHelper); + rWrtSh.KillSelection(nullptr, false); + } + } +} +} \ No newline at end of file diff --git a/sw/source/uibase/shells/textfld.cxx b/sw/source/uibase/shells/textfld.cxx index 7c840bb0670b..bd59cb048710 100644 --- a/sw/source/uibase/shells/textfld.cxx +++ b/sw/source/uibase/shells/textfld.cxx @@ -80,10 +80,9 @@ #include #include #include -#include #include #include - +#include static OUString lcl_BuildTitleWithRedline( const SwRangeRedline *pRedline ) { @@ -917,7 +916,7 @@ FIELD_INSERT: if (pFieldResult) { // Paste HTML content. - SwTranslateHelper::PasteHTMLToPaM(rSh, pCursorPos, aFieldResult.toUtf8()); + SwPam2Html::PasteHTMLToPaM(rSh, pCursorPos, aFieldResult.toUtf8()); if (pCursorPos->GetPoint()->GetContentIndex() == 0) { // The paste created a last empty text node, remove it. @@ -1083,7 +1082,7 @@ FIELD_INSERT: rSh.GetDoc()->getIDocumentContentOperations().DeleteAndJoin(aPaM); OUString aFieldResult; aMap[u"FieldResult"_ustr] >>= aFieldResult; - SwTranslateHelper::PasteHTMLToPaM(rSh, &aPaM, aFieldResult.toUtf8()); + SwPam2Html::PasteHTMLToPaM(rSh, &aPaM, aFieldResult.toUtf8()); } rSh.EndAction(); @@ -1578,7 +1577,7 @@ FIELD_INSERT: rSh.GetDoc()->getIDocumentContentOperations().DeleteAndJoin(aPaM); OUString aFieldResult; aMap[u"FieldResult"_ustr] >>= aFieldResult; - SwTranslateHelper::PasteHTMLToPaM(rSh, &aPaM, aFieldResult.toUtf8()); + SwPam2Html::PasteHTMLToPaM(rSh, &aPaM, aFieldResult.toUtf8()); rSh.EndAction(); rSh.GetDoc()->GetIDocumentUndoRedo().EndUndo(SwUndoId::UPDATE_FORM_FIELD, nullptr); diff --git a/sw/source/uibase/shells/textsh1.cxx b/sw/source/uibase/shells/textsh1.cxx index c74d0e4945df..c4b94ec13526 100644 --- a/sw/source/uibase/shells/textsh1.cxx +++ b/sw/source/uibase/shells/textsh1.cxx @@ -125,9 +125,7 @@ #if HAVE_FEATURE_CURL && !ENABLE_WASM_STRIP_EXTRA #include #include -#include #endif // HAVE_FEATURE_CURL && ENABLE_WASM_STRIP_EXTRA -#include #include #include #include @@ -141,6 +139,7 @@ #include #include #include +#include #include #include @@ -507,7 +506,7 @@ void UpdateSections(const SfxRequest& rReq, SwWrtShell& rWrtSh) rWrtSh.EndSelect(); OUString aSectionText = aMap[u"Content"_ustr].get(); - SwTranslateHelper::PasteHTMLToPaM(rWrtSh, pCursorPos, aSectionText.toUtf8()); + SwPam2Html::PasteHTMLToPaM(rWrtSh, pCursorPos, aSectionText.toUtf8()); } } @@ -619,7 +618,7 @@ void UpdateBookmarks(const SfxRequest& rReq, SwWrtShell& rWrtSh) // Paste HTML content. SwPaM* pCursorPos = rWrtSh.GetCursor(); *pCursorPos = aPasteEnd; - SwTranslateHelper::PasteHTMLToPaM(rWrtSh, pCursorPos, aBookmarkText.toUtf8()); + SwPam2Html::PasteHTMLToPaM(rWrtSh, pCursorPos, aBookmarkText.toUtf8()); // Update the bookmark to point to the new content. SwPaM aPasteStart(pMark->GetMarkEnd()); @@ -708,7 +707,7 @@ void UpdateBookmark(const SfxRequest& rReq, SwWrtShell& rWrtSh) // Paste HTML content. SwPaM* pCursorPos = rWrtSh.GetCursor(); *pCursorPos = aPasteEnd; - SwTranslateHelper::PasteHTMLToPaM(rWrtSh, pCursorPos, aBookmarkText.toUtf8()); + SwPam2Html::PasteHTMLToPaM(rWrtSh, pCursorPos, aBookmarkText.toUtf8()); // Update the bookmark to point to the new content. SwPaM aPasteStart(pBookmark->GetMarkEnd()); @@ -1366,8 +1365,7 @@ void SwTextShell::Execute(SfxRequest &rReq) aBookmarkPam.Move(fnMoveBackward, GoInContent); // Paste HTML content. - SwTranslateHelper::PasteHTMLToPaM( - rWrtSh, pCursorPos, aBookmarkText.toUtf8()); + SwPam2Html::PasteHTMLToPaM(rWrtSh, pCursorPos, aBookmarkText.toUtf8()); if (pCursorPos->GetPoint()->GetContentIndex() == 0) { // The paste created a last empty text node, remove it. @@ -2365,25 +2363,6 @@ void SwTextShell::Execute(SfxRequest &rReq) } } break; - case SID_FM_TRANSLATE: - { -#if HAVE_FEATURE_CURL && !ENABLE_WASM_STRIP_EXTRA - const SfxPoolItem* pTargetLangStringItem = nullptr; - if (pArgs && SfxItemState::SET == pArgs->GetItemState(SID_ATTR_TARGETLANG_STR, false, &pTargetLangStringItem)) - { - OString aTargetLang = OUStringToOString(static_cast(pTargetLangStringItem)->GetValue(), RTL_TEXTENCODING_UTF8); - SwTranslateHelper::TranslateDocument(rWrtSh, aTargetLang); - } - else - { - SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create(); - std::shared_ptr pAbstractDialog(pFact->CreateSwTranslateLangSelectDlg(GetView().GetFrameWeld(), rWrtSh)); - std::shared_ptr pDialogController(pAbstractDialog->getDialogController()); - weld::DialogController::runAsync(pDialogController, [] (sal_Int32 /*nResult*/) { }); - } -#endif // HAVE_FEATURE_CURL && ENABLE_WASM_STRIP_EXTRA - } - break; case SID_SPELLCHECK_IGNORE: { SwPaM *pPaM = rWrtSh.GetCursor(); @@ -4045,23 +4024,6 @@ void SwTextShell::GetState( SfxItemSet &rSet ) } break; - case SID_FM_TRANSLATE: - { -#if HAVE_FEATURE_CURL && !ENABLE_WASM_STRIP_EXTRA - if (!officecfg::Office::Common::Misc::ExperimentalMode::get() - && !comphelper::LibreOfficeKit::isActive()) - { - rSet.Put(SfxVisibilityItem(nWhich, false)); - break; - } - if (!SwTranslateHelper::IsTranslationServiceConfigured()) - { - rSet.DisableItem(nWhich); - } -#endif - } - break; - case SID_HYPERLINK_DIALOG: if( GetView().GetDocShell()->IsReadOnly() || ( !GetView().GetViewFrame().HasChildWindow(nWhich) diff --git a/sw/source/uibase/shells/translatehelper.cxx b/sw/source/uibase/shells/translatehelper.cxx deleted file mode 100644 index 19c746fab535..000000000000 --- a/sw/source/uibase/shells/translatehelper.cxx +++ /dev/null @@ -1,250 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * 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 . - */ - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace SwTranslateHelper -{ -OString ExportPaMToHTML(SwPaM* pCursor) -{ - SolarMutexGuard gMutex; - OString aResult; - WriterRef xWrt; - GetHTMLWriter(u"NoLineLimit,SkipHeaderFooter,NoPrettyPrint", OUString(), xWrt); - if (pCursor != nullptr) - { - SvMemoryStream aMemoryStream; - SwWriter aWriter(aMemoryStream, *pCursor); - ErrCodeMsg nError = aWriter.Write(xWrt); - if (nError.IsError()) - { - SAL_WARN("sw.ui", "ExportPaMToHTML: failed to export selection to HTML " << nError); - return {}; - } - aResult - = OString(static_cast(aMemoryStream.GetData()), aMemoryStream.GetSize()); - aResult = aResult.replaceAll(""_ostr, ""_ostr); - - // HTML has for that
and

also does new line - aResult = aResult.replaceAll("

    "_ostr, ""_ostr); - aResult = aResult.replaceAll("
"_ostr, ""_ostr); - aResult = aResult.replaceAll("
    "_ostr, ""_ostr); - aResult = aResult.replaceAll("
"_ostr, ""_ostr); - aResult = aResult.replaceAll("\n"_ostr, ""_ostr).trim(); - return aResult; - } - return {}; -} - -void PasteHTMLToPaM(SwWrtShell& rWrtSh, const SwPaM* pCursor, const OString& rData) -{ - SolarMutexGuard gMutex; - rtl::Reference pHtmlTransferable - = new vcl::unohelper::HtmlTransferable(rData); - if (pHtmlTransferable.is()) - { - TransferableDataHelper aDataHelper(pHtmlTransferable); - if (aDataHelper.GetXTransferable().is() - && SwTransferable::IsPasteSpecial(rWrtSh, aDataHelper)) - { - rWrtSh.SetSelection(*pCursor); - SwTransferable::Paste(rWrtSh, aDataHelper); - rWrtSh.KillSelection(nullptr, false); - } - } -} - -#if HAVE_FEATURE_CURL -void TranslateDocument(SwWrtShell& rWrtSh, const OString& rTargetLang) -{ - bool bCancel = false; - TranslateDocumentCancellable(rWrtSh, rTargetLang, bCancel); -} - -static bool IsTranslationServiceConfigured(OString* pAPIUrl, OString* pKey) -{ - auto oDeeplAPIUrl = officecfg::Office::Linguistic::Translation::Deepl::ApiURL::get(); - auto oDeeplKey = officecfg::Office::Linguistic::Translation::Deepl::AuthKey::get(); - auto sApiUrlTrimmed = oDeeplAPIUrl ? o3tl::trim(*oDeeplAPIUrl) : std::u16string_view(); - auto sKeyTrimmed = oDeeplKey ? o3tl::trim(*oDeeplKey) : std::u16string_view(); - if (sApiUrlTrimmed.empty() || sKeyTrimmed.empty()) - return false; - if (pAPIUrl) - *pAPIUrl = OUStringToOString(sApiUrlTrimmed, RTL_TEXTENCODING_UTF8) + "?tag_handling=html"; - if (pKey) - *pKey = OUStringToOString(sKeyTrimmed, RTL_TEXTENCODING_UTF8); - return true; -} - -bool IsTranslationServiceConfigured() { return IsTranslationServiceConfigured(nullptr, nullptr); } - -bool TranslateDocumentCancellable(SwWrtShell& rWrtSh, const OString& rTargetLang, - const bool& rCancelTranslation) -{ - OString aAPIUrl, aAuthKey; - if (!IsTranslationServiceConfigured(&aAPIUrl, &aAuthKey)) - { - SAL_WARN("sw.ui", "TranslateDocumentCancellable: API options are not set"); - return false; - } - - auto m_pCurrentPam = rWrtSh.GetCursor(); - bool bHasSelection = rWrtSh.HasSelection(); - - if (bHasSelection) - { - // iteration will start top to bottom - m_pCurrentPam->Normalize(); - } - - auto const& pNodes = rWrtSh.GetNodes(); - SwPosition aPoint = *m_pCurrentPam->GetPoint(); - SwPosition aMark = *m_pCurrentPam->GetMark(); - auto startNode = bHasSelection ? aPoint.nNode.GetIndex() : SwNodeOffset(0); - auto endNode = bHasSelection ? aMark.nNode.GetIndex() : pNodes.Count() - 1; - - sal_Int32 nCount(0); - sal_Int32 nProgress(0); - - for (SwNodeOffset n(startNode); n <= endNode; ++n) - { - if (pNodes[n] && pNodes[n]->IsTextNode()) - { - if (pNodes[n]->GetTextNode()->GetText().isEmpty()) - continue; - nCount++; - } - } - - SfxViewFrame* pFrame = SfxViewFrame::Current(); - uno::Reference xFrame(pFrame ? pFrame->GetFrame().GetFrameInterface() : nullptr); - uno::Reference xProgressFactory(xFrame, uno::UNO_QUERY); - uno::Reference xStatusIndicator; - - if (xProgressFactory.is()) - { - xStatusIndicator = xProgressFactory->createStatusIndicator(); - } - - if (xStatusIndicator.is()) - xStatusIndicator->start(SwResId(STR_STATSTR_SWTRANSLATE), nCount); - - for (SwNodeOffset n(startNode); n <= endNode; ++n) - { - if (rCancelTranslation) - break; - - if (n >= rWrtSh.GetNodes().Count()) - break; - - if (!pNodes[n]) - break; - - SwNode* pNode = pNodes[n]; - if (pNode->IsTextNode()) - { - if (pNode->GetTextNode()->GetText().isEmpty()) - continue; - - auto cursor - = Writer::NewUnoCursor(*rWrtSh.GetDoc(), pNode->GetIndex(), pNode->GetIndex()); - - // set edges (start, end) for nodes inside the selection. - if (bHasSelection) - { - if (startNode == endNode) - { - cursor->SetMark(); - cursor->GetPoint()->nContent = aPoint.nContent; - cursor->GetMark()->nContent = aMark.nContent; - } - else if (n == startNode) - { - cursor->SetMark(); - cursor->GetPoint()->nContent = aPoint.nContent; - } - else if (n == endNode) - { - cursor->SetMark(); - cursor->GetMark()->nContent = aMark.nContent; - cursor->GetPoint()->nContent = 0; - } - } - - const auto aOut = SwTranslateHelper::ExportPaMToHTML(cursor.get()); - const auto aTranslatedOut = linguistic::Translate(rTargetLang, aAPIUrl, aAuthKey, aOut); - if (!aTranslatedOut.isEmpty()) - { - SwTranslateHelper::PasteHTMLToPaM(rWrtSh, cursor.get(), aTranslatedOut); - } - else - { - std::unique_ptr xBox(Application::CreateMessageDialog( - nullptr, VclMessageType::Error, VclButtonsType::Ok, - SwResId(STR_SWTRANSLATE_ERROR))); - xBox->run(); - break; - } - - if (xStatusIndicator.is() && nCount) - xStatusIndicator->setValue((100 * ++nProgress) / nCount); - - Idle aIdle("TranslateDocumentCancellable aIdle"); - aIdle.SetPriority(TaskPriority::POST_PAINT); - aIdle.Start(); - - rWrtSh.LockView(true); - while (aIdle.IsActive() && !Application::IsQuit()) - { - Application::Yield(); - } - rWrtSh.LockView(false); - } - } - - if (xStatusIndicator.is()) - xStatusIndicator->end(); - return true; -} -#endif // HAVE_FEATURE_CURL -} diff --git a/sw/uiconfig/sglobal/menubar/menubar.xml b/sw/uiconfig/sglobal/menubar/menubar.xml index 2d573f761125..bb7519c372d2 100644 --- a/sw/uiconfig/sglobal/menubar/menubar.xml +++ b/sw/uiconfig/sglobal/menubar/menubar.xml @@ -725,8 +725,6 @@ - - diff --git a/sw/uiconfig/swriter/menubar/menubar.xml b/sw/uiconfig/swriter/menubar/menubar.xml index 04339aba003f..2024d9db801c 100644 --- a/sw/uiconfig/swriter/menubar/menubar.xml +++ b/sw/uiconfig/swriter/menubar/menubar.xml @@ -769,8 +769,6 @@ - - diff --git a/sw/uiconfig/swriter/ui/translationdialog.ui b/sw/uiconfig/swriter/ui/translationdialog.ui deleted file mode 100644 index 8bce7b2aa6d5..000000000000 --- a/sw/uiconfig/swriter/ui/translationdialog.ui +++ /dev/null @@ -1,119 +0,0 @@ - - - - - - False - 6 - Language Selection - False - True - 0 - 0 - dialog - - - False - vertical - 12 - - - False - end - - - _OK - True - True - True - True - - - False - True - 0 - - - - - _Cancel - True - True - True - True - - - False - True - 1 - - - - - _Help - True - True - True - True - - - False - True - 2 - True - - - - - False - False - 1 - - - - - - True - False - 6 - - - True - False - start - Select the target language for translation - True - combobox1 - - - 0 - 0 - - - - - True - False - True - - - 0 - 1 - - - - - False - False - 0 - - - - - - translate - cancel - help - - -