Resolves tdf#172375 - Revert "uno:Translate with DeepL API"

This reverts commit e20d2de783

* 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 <heiko.tietze@documentfoundation.org>
Tested-by: Jenkins
This commit is contained in:
Heiko Tietze
2026-06-21 06:51:52 +02:00
committed by Heiko Tietze
parent ca804630b3
commit 382b6f118c
39 changed files with 102 additions and 1129 deletions
-1
View File
@@ -192,7 +192,6 @@ $(eval $(call gb_Library_add_exception_objects,cui,\
cui/source/options/optgenrl \ cui/source/options/optgenrl \
cui/source/options/opthtml \ cui/source/options/opthtml \
cui/source/options/optlanguagetool \ cui/source/options/optlanguagetool \
cui/source/options/optdeepl \
cui/source/options/optinet2 \ cui/source/options/optinet2 \
cui/source/options/optjava \ cui/source/options/optjava \
cui/source/options/optjsearch \ cui/source/options/optjsearch \
-1
View File
@@ -137,7 +137,6 @@ $(eval $(call gb_UIConfig_add_uifiles,cui,\
cui/uiconfig/ui/optbasicidepage \ cui/uiconfig/ui/optbasicidepage \
cui/uiconfig/ui/optctlpage \ cui/uiconfig/ui/optctlpage \
cui/uiconfig/ui/optchartcolorspage \ cui/uiconfig/ui/optchartcolorspage \
cui/uiconfig/ui/optdeeplpage \
cui/uiconfig/ui/optemailpage \ cui/uiconfig/ui/optemailpage \
cui/uiconfig/ui/optfltrpage \ cui/uiconfig/ui/optfltrpage \
cui/uiconfig/ui/optfltrembedpage \ cui/uiconfig/ui/optfltrembedpage \
+1 -2
View File
@@ -54,8 +54,7 @@ const std::pair<TranslateId, sal_uInt16> SID_LANGUAGE_OPTIONS_RES[] =
{ NC_("SID_LANGUAGE_OPTIONS_RES", "Searching in Japanese"), RID_SVXPAGE_JSEARCH_OPTIONS }, { 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", "Asian Layout"), RID_SVXPAGE_ASIAN_LAYOUT },
{ NC_("SID_LANGUAGE_OPTIONS_RES", "Complex Text Layout"), RID_SVXPAGE_OPTIONS_CTL }, { 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", "LanguageTool Server"), RID_SVXPAGE_LANGTOOL_OPTIONS }
{ NC_("SID_LANGUAGE_OPTIONS_RES", "DeepL Server"), RID_SVXPAGE_DEEPL_OPTIONS }
}; };
const std::pair<TranslateId, sal_uInt16> SID_INET_DLG_RES[] = const std::pair<TranslateId, sal_uInt16> SID_INET_DLG_RES[] =
-82
View File
@@ -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 <officecfg/Office/Linguistic.hxx>
#include <rtl/ustrbuf.hxx>
#include <vcl/weld/Builder.hxx>
#include <vcl/weld/Label.hxx>
#include <vcl/weld/LinkButton.hxx>
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<OUString> 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<OUString> 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<comphelper::ConfigurationChanges> 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<SfxTabPage> OptDeeplTabPage::Create(weld::Container* pPage,
weld::DialogController* pController,
const SfxItemSet* rAttrSet)
{
return std::make_unique<OptDeeplTabPage>(pPage, pController, *rAttrSet);
}
-41
View File
@@ -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 <sfx2/tabdlg.hxx>
#include <vcl/weld/Entry.hxx>
class OptDeeplTabPage : public SfxTabPage
{
public:
OptDeeplTabPage(weld::Container* pPage, weld::DialogController* pController,
const SfxItemSet& rSet);
virtual ~OptDeeplTabPage() override;
static std::unique_ptr<SfxTabPage>
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<weld::Entry> m_xAPIUrl;
std::unique_ptr<weld::Entry> m_xAuthKey;
};
-9
View File
@@ -60,7 +60,6 @@
#include <treeopt.hxx> #include <treeopt.hxx>
#include "optbasic.hxx" #include "optbasic.hxx"
#include "optlanguagetool.hxx" #include "optlanguagetool.hxx"
#include "optdeepl.hxx"
// include search util // include search util
#include <com/sun/star/util/SearchFlags.hpp> #include <com/sun/star/util/SearchFlags.hpp>
@@ -270,7 +269,6 @@ static std::unique_ptr<SfxTabPage> CreateGeneralTabPage(sal_uInt16 nId, weld::Co
case RID_SVXPAGE_ACCESSIBILITYCONFIG: fnCreate = &SvxAccessibilityOptionsTabPage::Create; break; case RID_SVXPAGE_ACCESSIBILITYCONFIG: fnCreate = &SvxAccessibilityOptionsTabPage::Create; break;
case RID_SVXPAGE_OPTIONS_CTL: fnCreate = &SvxCTLOptionsPage::Create ; break; case RID_SVXPAGE_OPTIONS_CTL: fnCreate = &SvxCTLOptionsPage::Create ; break;
case RID_SVXPAGE_LANGTOOL_OPTIONS: fnCreate = &OptLanguageToolTabPage::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_OPTIONS_JAVA: fnCreate = &SvxJavaOptionsPage::Create ; break;
case RID_SVXPAGE_ONLINEUPDATE: fnCreate = &SvxOnlineUpdateTabPage::Create; break; case RID_SVXPAGE_ONLINEUPDATE: fnCreate = &SvxOnlineUpdateTabPage::Create; break;
case RID_OPTPAGE_CHART_DEFCOLORS: fnCreate = &SvxDefaultColorOptPage::Create; break; case RID_OPTPAGE_CHART_DEFCOLORS: fnCreate = &SvxDefaultColorOptPage::Create; break;
@@ -1775,13 +1773,6 @@ void OfaTreeOptionsDialog::languageOptions(const std::vector<sal_uInt16>& vPageI
if ( lcl_isOptionHidden( nPageId, aOptionsDlgOpt ) ) if ( lcl_isOptionHidden( nPageId, aOptionsDlgOpt ) )
continue; 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() ) && if ( ( RID_SVXPAGE_JSEARCH_OPTIONS != nPageId || SvtCJKOptions::IsJapaneseFindEnabled() ) &&
( RID_SVXPAGE_ASIAN_LAYOUT != nPageId || SvtCJKOptions::IsAsianTypographyEnabled() ) && ( RID_SVXPAGE_ASIAN_LAYOUT != nPageId || SvtCJKOptions::IsAsianTypographyEnabled() ) &&
( RID_SVXPAGE_OPTIONS_CTL != nPageId || SvtCTLOptions::IsCTLFontEnabled() ) ) ( RID_SVXPAGE_OPTIONS_CTL != nPageId || SvtCTLOptions::IsCTLFontEnabled() ) )
-1
View File
@@ -64,7 +64,6 @@ static PageIdToFileNameMap_Impl FileMap_Impl[] = {
{ RID_SVXPAGE_ASIAN_LAYOUT, u""_ustr }, // AsianLayout { RID_SVXPAGE_ASIAN_LAYOUT, u""_ustr }, // AsianLayout
{ RID_SVXPAGE_OPTIONS_CTL, u""_ustr }, // ComplexTextLayout { RID_SVXPAGE_OPTIONS_CTL, u""_ustr }, // ComplexTextLayout
{ RID_SVXPAGE_LANGTOOL_OPTIONS, u""_ustr }, // LanguageTool Server { RID_SVXPAGE_LANGTOOL_OPTIONS, u""_ustr }, // LanguageTool Server
{ RID_SVXPAGE_DEEPL_OPTIONS, u""_ustr }, // DeepL Server
// Internet, SID_INET_DLG // Internet, SID_INET_DLG
{ RID_SVXPAGE_INET_PROXY, u""_ustr }, // Proxy { RID_SVXPAGE_INET_PROXY, u""_ustr }, // Proxy
-129
View File
@@ -1,129 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.40.0 -->
<interface domain="cui">
<requires lib="gtk+" version="3.24"/>
<object class="GtkBox" id="OptDeeplPage">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<property name="border-width">6</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkFrame">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label-xalign">0</property>
<property name="shadow-type">none</property>
<child>
<!-- n-columns=1 n-rows=2 -->
<object class="GtkGrid" id="grid1">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="margin-start">12</property>
<property name="margin-top">6</property>
<property name="row-spacing">6</property>
<property name="column-spacing">12</property>
<child>
<object class="GtkLinkButton" id="privacy">
<property name="label" translatable="yes" context="optdeeplpage|privacy">Please read the privacy policy</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<property name="halign">start</property>
<property name="relief">none</property>
<property name="uri">https://www.deepl.com/privacy/</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">0</property>
</packing>
</child>
<child>
<!-- n-columns=2 n-rows=2 -->
<object class="GtkGrid" id="grid2">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="row-spacing">6</property>
<property name="column-spacing">12</property>
<child>
<object class="GtkLabel" id="label2">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes" context="optdeeplpage|privacy">API URL:</property>
<property name="use-underline">True</property>
<property name="mnemonic-widget">apiurl</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label3">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes" context="optdeeplpage|label3">Authentication key:</property>
<property name="use-underline">True</property>
<property name="mnemonic-widget">authkey</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">1</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="apiurl">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="hexpand">True</property>
<property name="truncate-multiline">True</property>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">0</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="authkey">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="hexpand">True</property>
<property name="truncate-multiline">True</property>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">1</property>
</packing>
</child>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">1</property>
</packing>
</child>
</object>
</child>
<child type="label">
<object class="GtkLabel" id="label1">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes" context="optdeeplpage|label1">DeepL API Options</property>
<property name="use-underline">True</property>
<property name="mnemonic-widget">grid1</property>
<attributes>
<attribute name="weight" value="bold"/>
</attributes>
</object>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
</interface>
-20
View File
@@ -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 <linguistic/lngdllapi.h>
#include <rtl/string.hxx>
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: */
-1
View File
@@ -56,7 +56,6 @@
#define RID_SVXPAGE_APPEARANCE (RID_SVX_START + 247) #define RID_SVXPAGE_APPEARANCE (RID_SVX_START + 247)
#define RID_SVXPAGE_BASICIDE_OPTIONS (RID_SVX_START + 209) #define RID_SVXPAGE_BASICIDE_OPTIONS (RID_SVX_START + 209)
#define RID_SVXPAGE_LANGTOOL_OPTIONS (RID_SVX_START + 210) #define RID_SVXPAGE_LANGTOOL_OPTIONS (RID_SVX_START + 210)
#define RID_SVXPAGE_DEEPL_OPTIONS (RID_SVX_START + 211)
// Resource-Id's ------------------------------------------------------------ // Resource-Id's ------------------------------------------------------------
+1 -1
View File
@@ -224,7 +224,7 @@ class SvxZoomItem;
#define SID_VIEW_DATA_SOURCE_BROWSER TypedWhichId<SfxBoolItem>(SID_SFX_START + 1660) #define SID_VIEW_DATA_SOURCE_BROWSER TypedWhichId<SfxBoolItem>(SID_SFX_START + 1660)
#define SID_UNPACK TypedWhichId<SfxBoolItem>(SID_SFX_START + 1662) #define SID_UNPACK TypedWhichId<SfxBoolItem>(SID_SFX_START + 1662)
// (SID_SFX_START + 1663) used further down // (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_GO_TO_PAGE (SID_SFX_START + 1665)
#define SID_OUTPUTSTREAM TypedWhichId<SfxUnoAnyItem>(SID_SFX_START + 1666) #define SID_OUTPUTSTREAM TypedWhichId<SfxUnoAnyItem>(SID_SFX_START + 1666)
#define SID_IMAGE_ORIENTATION TypedWhichId<SfxImageItem>(SID_SFX_START + 1667) #define SID_IMAGE_ORIENTATION TypedWhichId<SfxImageItem>(SID_SFX_START + 1667)
+1 -1
View File
@@ -604,7 +604,7 @@ class XFillGradientItem;
#define SID_FM_FILECONTROL ( SID_SVX_START + 605 ) #define SID_FM_FILECONTROL ( SID_SVX_START + 605 )
//( SID_SVX_START + 606 ) is used by SID_DRAWTBX_REDACTED_EXPORT //( SID_SVX_START + 606 ) is used by SID_DRAWTBX_REDACTED_EXPORT
#define SID_FM_NAVIGATIONBAR ( SID_SVX_START + 607 ) #define SID_FM_NAVIGATIONBAR ( SID_SVX_START + 607 )
#define SID_FM_TRANSLATE ( SID_SVX_START + 608 ) // was SID_FM_TRANSLATE introduced with e20d2de7836da52dbf9e528d1043b1e188097bfd
//FREE //FREE
#define SID_FM_DELETEROWS ( SID_SVX_START + 610 ) #define SID_FM_DELETEROWS ( SID_SVX_START + 610 )
//FREE //FREE
-1
View File
@@ -77,7 +77,6 @@ $(eval $(call gb_Library_add_exception_objects,lng,\
linguistic/source/spelldsp \ linguistic/source/spelldsp \
linguistic/source/spelldta \ linguistic/source/spelldta \
linguistic/source/thesdsp \ linguistic/source/thesdsp \
$(if $(ENABLE_CURL),linguistic/source/translate) \
)) ))
# vim: set noet sw=4 ts=4: # vim: set noet sw=4 ts=4:
-86
View File
@@ -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 <linguistic/translate.hxx>
#include <sal/log.hxx>
#include <curl/curl.h>
#include <rtl/string.h>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/json_parser.hpp>
#include <systools/curlinit.hxx>
#include <vcl/htmltransferable.hxx>
#include <tools/long.hxx>
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, std::function<void(CURL*)>> 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<std::string*>(userp);
size_t real_size = size * nmemb;
response->append(static_cast<char*>(buffer), real_size);
return real_size;
});
(void)curl_easy_setopt(curl.get(), CURLOPT_WRITEDATA, static_cast<void*>(&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<sal_Int32>(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<std::string>("text");
return OString(text);
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
@@ -1584,14 +1584,6 @@
<value>1</value> <value>1</value>
</prop> </prop>
</node> </node>
<node oor:name=".uno:Translate" oor:op="replace">
<prop oor:name="Label" oor:type="xs:string">
<value xml:lang="en-US">Translate...</value>
</prop>
<prop oor:name="Properties" oor:type="xs:int">
<value>1</value>
</prop>
</node>
<node oor:name=".uno:FormatColumns" oor:op="replace"> <node oor:name=".uno:FormatColumns" oor:op="replace">
<prop oor:name="Label" oor:type="xs:string"> <prop oor:name="Label" oor:type="xs:string">
<value xml:lang="en-US">Co~lumns...</value> <value xml:lang="en-US">Co~lumns...</value>
@@ -415,28 +415,6 @@
</prop> </prop>
</group> </group>
</group> </group>
<group oor:name="Translation">
<info>
<desc>Contains translation relevant settings.</desc>
</info>
<group oor:name="Deepl">
<info>
<desc>Contains DeepL API relevant settings.</desc>
</info>
<prop oor:name="ApiURL" oor:type="xs:string">
<info>
<desc>Deepl Translator API URL</desc>
<label>URL for the Deepl translator api</label>
</info>
</prop>
<prop oor:name="AuthKey" oor:type="xs:string">
<info>
<desc>Deepl Translator API URL Authkey</desc>
<label>Auth key for the Deepl translator api</label>
</info>
</prop>
</group>
</group>
<group oor:name="Hyphenation"> <group oor:name="Hyphenation">
<info> <info>
<desc>Contains hyphenation relevant settings.</desc> <desc>Contains hyphenation relevant settings.</desc>
-18
View File
@@ -1642,24 +1642,6 @@ SfxBoolItem NavigationBar SID_FM_NAVIGATIONBAR
GroupId = SfxGroupId::Controls; 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 SfxBoolItem Combobox SID_INSERT_COMBOBOX
[ [
+1 -1
View File
@@ -715,7 +715,7 @@ $(eval $(call gb_Library_add_exception_objects,sw,\
sw/source/uibase/shells/grfsh \ sw/source/uibase/shells/grfsh \
sw/source/uibase/shells/grfshex \ sw/source/uibase/shells/grfshex \
sw/source/uibase/shells/langhelper \ sw/source/uibase/shells/langhelper \
sw/source/uibase/shells/translatehelper \ sw/source/uibase/shells/pam2html \
sw/source/uibase/shells/listsh \ sw/source/uibase/shells/listsh \
sw/source/uibase/shells/mediash \ sw/source/uibase/shells/mediash \
sw/source/uibase/shells/navsh \ sw/source/uibase/shells/navsh \
-2
View File
@@ -80,7 +80,6 @@ $(eval $(call gb_Library_use_libraries,swui,\
vcl \ vcl \
drawinglayercore \ drawinglayercore \
drawinglayer \ drawinglayer \
lng \
)) ))
$(eval $(call gb_Library_add_exception_objects,swui,\ $(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/pgfnote \
sw/source/ui/misc/pggrid \ sw/source/ui/misc/pggrid \
sw/source/ui/misc/srtdlg \ sw/source/ui/misc/srtdlg \
$(if $(ENABLE_CURL),sw/source/ui/misc/translatelangselect) \
sw/source/ui/misc/swmodalredlineacceptdlg \ sw/source/ui/misc/swmodalredlineacceptdlg \
sw/source/ui/misc/titlepage \ sw/source/ui/misc/titlepage \
sw/source/ui/table/colwd \ sw/source/ui/table/colwd \
-1
View File
@@ -190,7 +190,6 @@ $(eval $(call gb_UIConfig_add_uifiles,modules/swriter,\
sw/uiconfig/swriter/ui/insertautotextdialog \ sw/uiconfig/swriter/ui/insertautotextdialog \
sw/uiconfig/swriter/ui/insertbookmark \ sw/uiconfig/swriter/ui/insertbookmark \
sw/uiconfig/swriter/ui/insertbreak \ sw/uiconfig/swriter/ui/insertbreak \
sw/uiconfig/swriter/ui/translationdialog \
sw/uiconfig/swriter/ui/insertcaption \ sw/uiconfig/swriter/ui/insertcaption \
sw/uiconfig/swriter/ui/insertdbcolumnsdialog \ sw/uiconfig/swriter/ui/insertdbcolumnsdialog \
sw/uiconfig/swriter/ui/insertfootnote \ sw/uiconfig/swriter/ui/insertfootnote \
-1
View File
@@ -300,7 +300,6 @@
#define STR_DELETE_NOTE_AUTHOR NC_("STR_DELETE_NOTE_AUTHOR", "Delete ~All Comments by $1") #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_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_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.") #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 /* To translators: $1 == will be replaced by STR_WORDCOUNT_WORDARG, and $2 by STR_WORDCOUNT_COLARG
e.g. Selected: 1 word, 2 characters */ e.g. Selected: 1 word, 2 characters */
-12
View File
@@ -412,17 +412,6 @@ public:
virtual sal_uInt16 GetRestartPage() const = 0; virtual sal_uInt16 GetRestartPage() const = 0;
}; };
class SwLanguageListItem;
class AbstractSwTranslateLangSelectDlg
{
protected:
virtual ~AbstractSwTranslateLangSelectDlg() = default;
public:
virtual std::shared_ptr<weld::DialogController> getDialogController() = 0;
virtual std::optional<SwLanguageListItem> GetSelectedLanguage() = 0;
};
class AbstractSwSortDlg : public VclAbstractDialog class AbstractSwSortDlg : public VclAbstractDialog
{ {
protected: protected:
@@ -494,7 +483,6 @@ public:
CreateSwContentControlListItemDlg(weld::Window* pParent, SwContentControlListItem& rItem) = 0; CreateSwContentControlListItemDlg(weld::Window* pParent, SwContentControlListItem& rItem) = 0;
virtual std::shared_ptr<AbstractSwBreakDlg> CreateSwBreakDlg(weld::Window *pParent, SwWrtShell &rSh) = 0; virtual std::shared_ptr<AbstractSwBreakDlg> CreateSwBreakDlg(weld::Window *pParent, SwWrtShell &rSh) = 0;
virtual std::shared_ptr<AbstractSwTranslateLangSelectDlg> CreateSwTranslateLangSelectDlg(weld::Window *pParent, SwWrtShell &rSh) = 0;
virtual VclPtr<AbstractChangeDbDialog> CreateSwChangeDBDlg(SwView& rVw) = 0; virtual VclPtr<AbstractChangeDbDialog> CreateSwChangeDBDlg(SwView& rVw) = 0;
virtual VclPtr<SfxAbstractTabDialog> CreateSwCharDlg(weld::Window* pParent, SwView& rView, const SfxItemSet& rCoreSet, virtual VclPtr<SfxAbstractTabDialog> CreateSwCharDlg(weld::Window* pParent, SwView& rView, const SfxItemSet& rCoreSet,
SwCharDlgMode nDialogMode, const OUString* pFormatStr = nullptr) = 0; SwCharDlgMode nDialogMode, const OUString* pFormatStr = nullptr) = 0;
-6
View File
@@ -1971,11 +1971,5 @@ FN_INSERT_LANDSCAPE_PAGE // status(final|play)
StateMethod = GetState ; StateMethod = GetState ;
] ]
SID_FM_TRANSLATE
[
ExecMethod = Execute ;
StateMethod = GetState ;
]
} // end of interface text } // end of interface text
+2 -2
View File
@@ -33,7 +33,7 @@
#include <doc.hxx> #include <doc.hxx>
#include <ndtxt.hxx> #include <ndtxt.hxx>
#include <pam.hxx> #include <pam.hxx>
#include <translatehelper.hxx> #include <pam2html.hxx>
#include <wrtsh.hxx> #include <wrtsh.hxx>
SwFormatRefMark::~SwFormatRefMark( ) SwFormatRefMark::~SwFormatRefMark( )
@@ -187,7 +187,7 @@ void SwTextRefMark::UpdateFieldContent(SwDoc* pDoc, SwWrtShell& rWrtSh, const OU
// Paste HTML content. // Paste HTML content.
SwPaM* pCursorPos = rWrtSh.GetCursor(); SwPaM* pCursorPos = rWrtSh.GetCursor();
*pCursorPos = aPasteEnd; *pCursorPos = aPasteEnd;
SwTranslateHelper::PasteHTMLToPaM(rWrtSh, pCursorPos, aContent.toUtf8()); SwPam2Html::PasteHTMLToPaM(rWrtSh, pCursorPos, aContent.toUtf8());
// Update the refmark to point to the new content. // Update the refmark to point to the new content.
sal_Int32 nOldStart = this->GetStart(); sal_Int32 nOldStart = this->GetStart();
-35
View File
@@ -91,7 +91,6 @@
#include <uiborder.hxx> #include <uiborder.hxx>
#include <mmresultdialogs.hxx> #include <mmresultdialogs.hxx>
#include <formatlinebreak.hxx> #include <formatlinebreak.hxx>
#include <translatelangselect.hxx>
#include <copyfielddlg.hxx> #include <copyfielddlg.hxx>
#include <SwGridTabPage.hxx> #include <SwGridTabPage.hxx>
#include <set> #include <set>
@@ -131,20 +130,6 @@ public:
std::shared_ptr<weld::DialogController> getDialogController() override { return m_xDlg; } std::shared_ptr<weld::DialogController> getDialogController() override { return m_xDlg; }
}; };
class AbstractSwTranslateLangSelectDlg_Impl : public AbstractSwTranslateLangSelectDlg
{
std::shared_ptr<weld::DialogController> m_xDlg;
public:
explicit AbstractSwTranslateLangSelectDlg_Impl(std::shared_ptr<weld::DialogController> p)
: m_xDlg(std::move(p))
{
}
std::shared_ptr<weld::DialogController> getDialogController() override { return m_xDlg; }
std::optional<SwLanguageListItem> GetSelectedLanguage() override;
};
class AbstractInsTableDlg_Impl : public AbstractInsTableDlg class AbstractInsTableDlg_Impl : public AbstractInsTableDlg
{ {
std::shared_ptr<weld::DialogController> m_xDlg; std::shared_ptr<weld::DialogController> m_xDlg;
@@ -206,15 +191,6 @@ void AbstractInsTableDlg_Impl::GetValues( OUString& rName, sal_uInt16& rRow, sal
pDlg->GetValues(rName, rRow, rCol, rInsTableFlags, rTableAutoFormatName, prTAFormat); pDlg->GetValues(rName, rRow, rCol, rInsTableFlags, rTableAutoFormatName, prTAFormat);
} }
std::optional<SwLanguageListItem> AbstractSwTranslateLangSelectDlg_Impl::GetSelectedLanguage()
{
#if HAVE_FEATURE_CURL && !ENABLE_WASM_STRIP_EXTRA
return SwTranslateLangSelectDlg::GetSelectedLanguage();
#else
return {};
#endif
}
namespace namespace
{ {
class AbstractSwInsertAbstractDlg_Impl class AbstractSwInsertAbstractDlg_Impl
@@ -329,17 +305,6 @@ std::shared_ptr<AbstractSwBreakDlg> SwAbstractDialogFactory_Impl::CreateSwBreakD
return std::make_shared<AbstractSwBreakDlg_Impl>(std::make_unique<SwBreakDlg>(pParent, rSh)); return std::make_shared<AbstractSwBreakDlg_Impl>(std::make_unique<SwBreakDlg>(pParent, rSh));
} }
std::shared_ptr<AbstractSwTranslateLangSelectDlg> SwAbstractDialogFactory_Impl::CreateSwTranslateLangSelectDlg(weld::Window* pParent, SwWrtShell &rSh)
{
#if HAVE_FEATURE_CURL && !ENABLE_WASM_STRIP_EXTRA
return std::make_shared<AbstractSwTranslateLangSelectDlg_Impl>(std::make_unique<SwTranslateLangSelectDlg>(pParent, rSh));
#else
(void) pParent;
(void) rSh;
return nullptr;
#endif
}
namespace namespace
{ {
class AbstractChangeDbDialog_Impl class AbstractChangeDbDialog_Impl
-1
View File
@@ -83,7 +83,6 @@ public:
SwContentControlListItem& rItem) override; SwContentControlListItem& rItem) override;
virtual std::shared_ptr<AbstractSwBreakDlg> CreateSwBreakDlg(weld::Window *pParent, SwWrtShell &rSh) override; virtual std::shared_ptr<AbstractSwBreakDlg> CreateSwBreakDlg(weld::Window *pParent, SwWrtShell &rSh) override;
virtual std::shared_ptr<AbstractSwTranslateLangSelectDlg> CreateSwTranslateLangSelectDlg(weld::Window *pParent, SwWrtShell &rSh) override;
virtual VclPtr<AbstractChangeDbDialog> CreateSwChangeDBDlg(SwView& rVw) override; virtual VclPtr<AbstractChangeDbDialog> CreateSwChangeDBDlg(SwView& rVw) override;
virtual VclPtr<SfxAbstractTabDialog> CreateSwCharDlg(weld::Window* pParent, SwView& pVw, const SfxItemSet& rCoreSet, virtual VclPtr<SfxAbstractTabDialog> CreateSwCharDlg(weld::Window* pParent, SwView& pVw, const SfxItemSet& rCoreSet,
SwCharDlgMode nDialogMode, const OUString* pFormatStr = nullptr) override; SwCharDlgMode nDialogMode, const OUString* pFormatStr = nullptr) override;
-136
View File
@@ -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 <sal/config.h>
#include <vcl/svapp.hxx>
#include <vcl/vclenum.hxx>
#include <vcl/weld/Builder.hxx>
#include <vcl/weld/Dialog.hxx>
#include <uitool.hxx>
#include <translatelangselect.hxx>
#include <translatehelper.hxx>
static const std::vector<SwLanguageListItem>& getLanguageVec()
{
static const std::vector<SwLanguageListItem> 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<SwLanguageListItem> 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: */
+2 -2
View File
@@ -33,8 +33,8 @@
#include <cmdid.h> #include <cmdid.h>
#include <swabstdlg.hxx> #include <swabstdlg.hxx>
#include <IDocumentContentOperations.hxx> #include <IDocumentContentOperations.hxx>
#include <translatehelper.hxx>
#include <IDocumentUndoRedo.hxx> #include <IDocumentUndoRedo.hxx>
#include <pam2html.hxx>
void SwBaseShell::InsertRegionDialog(SfxRequest& rReq) void SwBaseShell::InsertRegionDialog(SfxRequest& rReq)
{ {
@@ -160,7 +160,7 @@ void SwBaseShell::InsertRegionDialog(SfxRequest& rReq)
SwPaM* pCursorPos = rSh.GetCursor(); SwPaM* pCursorPos = rSh.GetCursor();
pCursorPos->Move(fnMoveBackward, GoInContent); pCursorPos->Move(fnMoveBackward, GoInContent);
// Paste HTML content. // Paste HTML content.
SwTranslateHelper::PasteHTMLToPaM(rSh, pCursorPos, aSectionContent.toUtf8()); SwPam2Html::PasteHTMLToPaM(rSh, pCursorPos, aSectionContent.toUtf8());
if (pCursorPos->GetPoint()->GetContentIndex() == 0) if (pCursorPos->GetPoint()->GetContentIndex() == 0)
{ {
// The paste created a last empty text node, remove it. // The paste created a last empty text node, remove it.
+2 -2
View File
@@ -74,13 +74,13 @@
#include <tox.hxx> #include <tox.hxx>
#include <viewopt.hxx> #include <viewopt.hxx>
#include <txmsrt.hxx> #include <txmsrt.hxx>
#include <pam2html.hxx>
#include <unotools/useroptions.hxx> #include <unotools/useroptions.hxx>
#include <IDocumentContentOperations.hxx> #include <IDocumentContentOperations.hxx>
#if ENABLE_YRS #if ENABLE_YRS
#include <IDocumentState.hxx> #include <IDocumentState.hxx>
#include <txtfld.hxx> #include <txtfld.hxx>
#endif #endif
#include <translatehelper.hxx>
#include <txtrfmrk.hxx> #include <txtrfmrk.hxx>
using namespace com::sun::star::uno; using namespace com::sun::star::uno;
@@ -1091,7 +1091,7 @@ bool SwFieldMgr::InsertField(
aRefmarkPam.Move(fnMoveBackward, GoInContent); aRefmarkPam.Move(fnMoveBackward, GoInContent);
// Paste HTML content. // Paste HTML content.
SwTranslateHelper::PasteHTMLToPaM( SwPam2Html::PasteHTMLToPaM(
*pCurShell, pCursorPos, rRefmarkText.toUtf8()); *pCurShell, pCursorPos, rRefmarkText.toUtf8());
// Undo the above SplitNode(). // Undo the above SplitNode().
@@ -22,21 +22,12 @@
#include <config_features.h> #include <config_features.h>
#include <rtl/string.hxx>
#include <swdllapi.h> #include <swdllapi.h>
class SwWrtShell; namespace SwPam2Html
class SwPaM;
namespace SwTranslateHelper
{ {
SW_DLLPUBLIC OString ExportPaMToHTML(SwPaM* pCursor); SW_DLLPUBLIC OString ExportPaMToHTML(SwPaM* pCursor);
SW_DLLPUBLIC void PasteHTMLToPaM(SwWrtShell& rWrtSh, const SwPaM* pCursor, const OString& rData); 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: */
@@ -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 <vcl/weld/Button.hxx>
#include <vcl/weld/ComboBox.hxx>
#include <vcl/weld/DialogController.hxx>
#include <vcl/weld/Window.hxx>
#include <rtl/string.hxx>
#include <optional>
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<SwLanguageListItem> GetSelectedLanguage();
private:
SwWrtShell& m_rWrtSh;
std::unique_ptr<weld::ComboBox> m_xLanguageListBox;
std::unique_ptr<weld::Button> m_xBtnCancel;
std::unique_ptr<weld::Button> 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: */
-1
View File
@@ -121,7 +121,6 @@
#include <UndoManager.hxx> #include <UndoManager.hxx>
#include <fmtrfmrk.hxx> #include <fmtrfmrk.hxx>
#include <txtrfmrk.hxx> #include <txtrfmrk.hxx>
#include <translatehelper.hxx>
#include <rootfrm.hxx> #include <rootfrm.hxx>
FlyMode SwBaseShell::s_eFrameMode = FLY_DRAG_END; FlyMode SwBaseShell::s_eFrameMode = FLY_DRAG_END;
+80
View File
@@ -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 <sal/config.h>
#include <config_features.h>
#include <shellio.hxx>
#include <swdtflvr.hxx>
#include <wrtsh.hxx>
#include <vcl/htmltransferable.hxx>
#include <pam2html.hxx>
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<const char*>(aMemoryStream.GetData()), aMemoryStream.GetSize());
aResult = aResult.replaceAll("<p"_ostr, "<span"_ostr);
aResult = aResult.replaceAll("</p>"_ostr, "</span>"_ostr);
// HTML has for that <br> and <p> also does new line
aResult = aResult.replaceAll("<ul>"_ostr, ""_ostr);
aResult = aResult.replaceAll("</ul>"_ostr, ""_ostr);
aResult = aResult.replaceAll("<ol>"_ostr, ""_ostr);
aResult = aResult.replaceAll("</ol>"_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<vcl::unohelper::HtmlTransferable> 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);
}
}
}
}
+4 -5
View File
@@ -80,10 +80,9 @@
#include <officecfg/Office/Common.hxx> #include <officecfg/Office/Common.hxx>
#include <officecfg/Office/Compatibility.hxx> #include <officecfg/Office/Compatibility.hxx>
#include <ndtxt.hxx> #include <ndtxt.hxx>
#include <translatehelper.hxx>
#include <sfx2/dispatch.hxx> #include <sfx2/dispatch.hxx>
#include <vcl/svapp.hxx> #include <vcl/svapp.hxx>
#include <pam2html.hxx>
static OUString lcl_BuildTitleWithRedline( const SwRangeRedline *pRedline ) static OUString lcl_BuildTitleWithRedline( const SwRangeRedline *pRedline )
{ {
@@ -917,7 +916,7 @@ FIELD_INSERT:
if (pFieldResult) if (pFieldResult)
{ {
// Paste HTML content. // Paste HTML content.
SwTranslateHelper::PasteHTMLToPaM(rSh, pCursorPos, aFieldResult.toUtf8()); SwPam2Html::PasteHTMLToPaM(rSh, pCursorPos, aFieldResult.toUtf8());
if (pCursorPos->GetPoint()->GetContentIndex() == 0) if (pCursorPos->GetPoint()->GetContentIndex() == 0)
{ {
// The paste created a last empty text node, remove it. // The paste created a last empty text node, remove it.
@@ -1083,7 +1082,7 @@ FIELD_INSERT:
rSh.GetDoc()->getIDocumentContentOperations().DeleteAndJoin(aPaM); rSh.GetDoc()->getIDocumentContentOperations().DeleteAndJoin(aPaM);
OUString aFieldResult; OUString aFieldResult;
aMap[u"FieldResult"_ustr] >>= aFieldResult; aMap[u"FieldResult"_ustr] >>= aFieldResult;
SwTranslateHelper::PasteHTMLToPaM(rSh, &aPaM, aFieldResult.toUtf8()); SwPam2Html::PasteHTMLToPaM(rSh, &aPaM, aFieldResult.toUtf8());
} }
rSh.EndAction(); rSh.EndAction();
@@ -1578,7 +1577,7 @@ FIELD_INSERT:
rSh.GetDoc()->getIDocumentContentOperations().DeleteAndJoin(aPaM); rSh.GetDoc()->getIDocumentContentOperations().DeleteAndJoin(aPaM);
OUString aFieldResult; OUString aFieldResult;
aMap[u"FieldResult"_ustr] >>= aFieldResult; aMap[u"FieldResult"_ustr] >>= aFieldResult;
SwTranslateHelper::PasteHTMLToPaM(rSh, &aPaM, aFieldResult.toUtf8()); SwPam2Html::PasteHTMLToPaM(rSh, &aPaM, aFieldResult.toUtf8());
rSh.EndAction(); rSh.EndAction();
rSh.GetDoc()->GetIDocumentUndoRedo().EndUndo(SwUndoId::UPDATE_FORM_FIELD, nullptr); rSh.GetDoc()->GetIDocumentUndoRedo().EndUndo(SwUndoId::UPDATE_FORM_FIELD, nullptr);
+5 -43
View File
@@ -125,9 +125,7 @@
#if HAVE_FEATURE_CURL && !ENABLE_WASM_STRIP_EXTRA #if HAVE_FEATURE_CURL && !ENABLE_WASM_STRIP_EXTRA
#include <officecfg/Office/Common.hxx> #include <officecfg/Office/Common.hxx>
#include <svl/visitem.hxx> #include <svl/visitem.hxx>
#include <translatelangselect.hxx>
#endif // HAVE_FEATURE_CURL && ENABLE_WASM_STRIP_EXTRA #endif // HAVE_FEATURE_CURL && ENABLE_WASM_STRIP_EXTRA
#include <translatehelper.hxx>
#include <IDocumentContentOperations.hxx> #include <IDocumentContentOperations.hxx>
#include <IDocumentUndoRedo.hxx> #include <IDocumentUndoRedo.hxx>
#include <fmtcntnt.hxx> #include <fmtcntnt.hxx>
@@ -141,6 +139,7 @@
#include <unotxdoc.hxx> #include <unotxdoc.hxx>
#include <expfld.hxx> #include <expfld.hxx>
#include <sax/tools/converter.hxx> #include <sax/tools/converter.hxx>
#include <pam2html.hxx>
#include <com/sun/star/text/XTextEmbeddedObjectsSupplier.hpp> #include <com/sun/star/text/XTextEmbeddedObjectsSupplier.hpp>
#include <com/sun/star/chart2/XInternalDataProvider.hpp> #include <com/sun/star/chart2/XInternalDataProvider.hpp>
@@ -507,7 +506,7 @@ void UpdateSections(const SfxRequest& rReq, SwWrtShell& rWrtSh)
rWrtSh.EndSelect(); rWrtSh.EndSelect();
OUString aSectionText = aMap[u"Content"_ustr].get<OUString>(); OUString aSectionText = aMap[u"Content"_ustr].get<OUString>();
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. // Paste HTML content.
SwPaM* pCursorPos = rWrtSh.GetCursor(); SwPaM* pCursorPos = rWrtSh.GetCursor();
*pCursorPos = aPasteEnd; *pCursorPos = aPasteEnd;
SwTranslateHelper::PasteHTMLToPaM(rWrtSh, pCursorPos, aBookmarkText.toUtf8()); SwPam2Html::PasteHTMLToPaM(rWrtSh, pCursorPos, aBookmarkText.toUtf8());
// Update the bookmark to point to the new content. // Update the bookmark to point to the new content.
SwPaM aPasteStart(pMark->GetMarkEnd()); SwPaM aPasteStart(pMark->GetMarkEnd());
@@ -708,7 +707,7 @@ void UpdateBookmark(const SfxRequest& rReq, SwWrtShell& rWrtSh)
// Paste HTML content. // Paste HTML content.
SwPaM* pCursorPos = rWrtSh.GetCursor(); SwPaM* pCursorPos = rWrtSh.GetCursor();
*pCursorPos = aPasteEnd; *pCursorPos = aPasteEnd;
SwTranslateHelper::PasteHTMLToPaM(rWrtSh, pCursorPos, aBookmarkText.toUtf8()); SwPam2Html::PasteHTMLToPaM(rWrtSh, pCursorPos, aBookmarkText.toUtf8());
// Update the bookmark to point to the new content. // Update the bookmark to point to the new content.
SwPaM aPasteStart(pBookmark->GetMarkEnd()); SwPaM aPasteStart(pBookmark->GetMarkEnd());
@@ -1366,8 +1365,7 @@ void SwTextShell::Execute(SfxRequest &rReq)
aBookmarkPam.Move(fnMoveBackward, GoInContent); aBookmarkPam.Move(fnMoveBackward, GoInContent);
// Paste HTML content. // Paste HTML content.
SwTranslateHelper::PasteHTMLToPaM( SwPam2Html::PasteHTMLToPaM(rWrtSh, pCursorPos, aBookmarkText.toUtf8());
rWrtSh, pCursorPos, aBookmarkText.toUtf8());
if (pCursorPos->GetPoint()->GetContentIndex() == 0) if (pCursorPos->GetPoint()->GetContentIndex() == 0)
{ {
// The paste created a last empty text node, remove it. // The paste created a last empty text node, remove it.
@@ -2365,25 +2363,6 @@ void SwTextShell::Execute(SfxRequest &rReq)
} }
} }
break; 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<const SfxStringItem*>(pTargetLangStringItem)->GetValue(), RTL_TEXTENCODING_UTF8);
SwTranslateHelper::TranslateDocument(rWrtSh, aTargetLang);
}
else
{
SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
std::shared_ptr<AbstractSwTranslateLangSelectDlg> pAbstractDialog(pFact->CreateSwTranslateLangSelectDlg(GetView().GetFrameWeld(), rWrtSh));
std::shared_ptr<weld::DialogController> pDialogController(pAbstractDialog->getDialogController());
weld::DialogController::runAsync(pDialogController, [] (sal_Int32 /*nResult*/) { });
}
#endif // HAVE_FEATURE_CURL && ENABLE_WASM_STRIP_EXTRA
}
break;
case SID_SPELLCHECK_IGNORE: case SID_SPELLCHECK_IGNORE:
{ {
SwPaM *pPaM = rWrtSh.GetCursor(); SwPaM *pPaM = rWrtSh.GetCursor();
@@ -4045,23 +4024,6 @@ void SwTextShell::GetState( SfxItemSet &rSet )
} }
break; 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: case SID_HYPERLINK_DIALOG:
if( GetView().GetDocShell()->IsReadOnly() if( GetView().GetDocShell()->IsReadOnly()
|| ( !GetView().GetViewFrame().HasChildWindow(nWhich) || ( !GetView().GetViewFrame().HasChildWindow(nWhich)
-250
View File
@@ -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 <sal/config.h>
#include <config_features.h>
#include <wrtsh.hxx>
#include <pam.hxx>
#include <node.hxx>
#include <ndtxt.hxx>
#include <translatehelper.hxx>
#include <o3tl/string_view.hxx>
#include <sal/log.hxx>
#include <rtl/string.h>
#include <shellio.hxx>
#include <vcl/svapp.hxx>
#include <vcl/htmltransferable.hxx>
#include <vcl/transfer.hxx>
#include <vcl/weld/MessageDialog.hxx>
#include <swdtflvr.hxx>
#include <linguistic/translate.hxx>
#include <com/sun/star/frame/XModel3.hpp>
#include <com/sun/star/task/XStatusIndicator.hpp>
#include <sfx2/viewfrm.hxx>
#include <com/sun/star/task/XStatusIndicatorFactory.hpp>
#include <officecfg/Office/Linguistic.hxx>
#include <strings.hrc>
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<const char*>(aMemoryStream.GetData()), aMemoryStream.GetSize());
aResult = aResult.replaceAll("<p"_ostr, "<span"_ostr);
aResult = aResult.replaceAll("</p>"_ostr, "</span>"_ostr);
// HTML has for that <br> and <p> also does new line
aResult = aResult.replaceAll("<ul>"_ostr, ""_ostr);
aResult = aResult.replaceAll("</ul>"_ostr, ""_ostr);
aResult = aResult.replaceAll("<ol>"_ostr, ""_ostr);
aResult = aResult.replaceAll("</ol>"_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<vcl::unohelper::HtmlTransferable> 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<frame::XFrame> xFrame(pFrame ? pFrame->GetFrame().GetFrameInterface() : nullptr);
uno::Reference<task::XStatusIndicatorFactory> xProgressFactory(xFrame, uno::UNO_QUERY);
uno::Reference<task::XStatusIndicator> 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<weld::MessageDialog> 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
}
-2
View File
@@ -725,8 +725,6 @@
<menu:menuitem menu:id=".uno:AccessibilityCheck" menu:style="text"/> <menu:menuitem menu:id=".uno:AccessibilityCheck" menu:style="text"/>
<menu:menuitem menu:id=".uno:AccessibilityCheckOnline" menu:style="text"/> <menu:menuitem menu:id=".uno:AccessibilityCheckOnline" menu:style="text"/>
<menu:menuseparator/> <menu:menuseparator/>
<menu:menuitem menu:id=".uno:Translate" menu:style="text"/>
<menu:menuseparator/>
<menu:menu menu:id=".uno:AutoFormatMenu"> <menu:menu menu:id=".uno:AutoFormatMenu">
<menu:menupopup> <menu:menupopup>
<menu:menuitem menu:id=".uno:OnlineAutoFormat"/> <menu:menuitem menu:id=".uno:OnlineAutoFormat"/>
-2
View File
@@ -769,8 +769,6 @@
<menu:menuitem menu:id=".uno:AccessibilityCheck" menu:style="text"/> <menu:menuitem menu:id=".uno:AccessibilityCheck" menu:style="text"/>
<menu:menuitem menu:id=".uno:AccessibilityCheckOnline" menu:style="text"/> <menu:menuitem menu:id=".uno:AccessibilityCheckOnline" menu:style="text"/>
<menu:menuseparator/> <menu:menuseparator/>
<menu:menuitem menu:id=".uno:Translate" menu:style="text"/>
<menu:menuseparator/>
<menu:menu menu:id=".uno:AutoFormatMenu"> <menu:menu menu:id=".uno:AutoFormatMenu">
<menu:menupopup> <menu:menupopup>
<menu:menuitem menu:id=".uno:OnlineAutoFormat"/> <menu:menuitem menu:id=".uno:OnlineAutoFormat"/>
-119
View File
@@ -1,119 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.40.0 -->
<interface domain="sw">
<requires lib="gtk+" version="3.24"/>
<object class="GtkDialog" id="LanguageSelectDialog">
<property name="can-focus">False</property>
<property name="border-width">6</property>
<property name="title" translatable="yes" context="LanguageSelectDialog">Language Selection</property>
<property name="resizable">False</property>
<property name="modal">True</property>
<property name="default-width">0</property>
<property name="default-height">0</property>
<property name="type-hint">dialog</property>
<child internal-child="vbox">
<object class="GtkBox" id="dialog-vbox1">
<property name="can-focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">12</property>
<child internal-child="action_area">
<object class="GtkButtonBox" id="action-area1">
<property name="can-focus">False</property>
<property name="layout-style">end</property>
<child>
<object class="GtkButton" id="translate">
<property name="label" translatable="yes" context="stock">_OK</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<property name="use-underline">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="cancel">
<property name="label" translatable="yes" context="stock">_Cancel</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<property name="use-underline">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkButton" id="help">
<property name="label" translatable="yes" context="stock">_Help</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<property name="use-underline">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
<property name="secondary">True</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
<child>
<!-- n-columns=1 n-rows=2 -->
<object class="GtkGrid" id="grid1">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="row-spacing">6</property>
<child>
<object class="GtkLabel" id="label1">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes" context="LanguageSelectDialog">Select the target language for translation</property>
<property name="use-underline">True</property>
<property name="mnemonic-widget">combobox1</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">0</property>
</packing>
</child>
<child>
<object class="GtkComboBoxText" id="combobox1">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="hexpand">True</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
</object>
</child>
<action-widgets>
<action-widget response="-5">translate</action-widget>
<action-widget response="-6">cancel</action-widget>
<action-widget response="-11">help</action-widget>
</action-widgets>
</object>
</interface>