summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorMert Tumer <mert.tumer@collabora.com>2022-07-05 12:03:27 +0300
committerMiklos Vajna <vmiklos@collabora.com>2022-10-12 16:52:03 +0200
commite20d2de7836da52dbf9e528d1043b1e188097bfd (patch)
treecec9878830ff561c6d9eb492aa25eb8e8b49876a /include
parentd75f27fd738eeb2c7dc6d22f198d55d3a877aa0b (diff)
new uno command uno:Translate with deepl api
New Uno command added for translation right now it is only using deepl translation api There's a section in the options > language settings for setting up the api url and auth key uno:Translate is a menu button under Format tab which will bring up Language Selection dialog for translation. DeepL can accept html as the input for translation, this new feature leverages that by exporting paragraphs/selections to html and paste them back without losing the formatting (in theory) This works good in general but we may lose formatting in very complex styled sentences. Translation works in two ways; 1) Whole document when there is no selection, it assumes that we want to translate whole document. Each paragraphs is sent one by one so that the output timeout can be minimum for each paragraph. 2) Selection Change-Id: Ia2d3ab2f6757faf565b939e1d670a7dedac33390 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/140624 Tested-by: Jenkins Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Diffstat (limited to 'include')
-rw-r--r--include/linguistic/translate.hxx9
-rw-r--r--include/sfx2/pageids.hxx1
-rw-r--r--include/sfx2/sfxsids.hrc1
-rw-r--r--include/svtools/deeplcfg.hxx50
-rw-r--r--include/svx/svxids.hrc2
-rw-r--r--include/vcl/htmltransferable.hxx51
6 files changed, 113 insertions, 1 deletions
diff --git a/include/linguistic/translate.hxx b/include/linguistic/translate.hxx
new file mode 100644
index 000000000000..985930c74d83
--- /dev/null
+++ b/include/linguistic/translate.hxx
@@ -0,0 +1,9 @@
+#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
diff --git a/include/sfx2/pageids.hxx b/include/sfx2/pageids.hxx
index 9371848b784a..1464ec40c55a 100644
--- a/include/sfx2/pageids.hxx
+++ b/include/sfx2/pageids.hxx
@@ -57,6 +57,7 @@
#define RID_SVXPAGE_COLORCONFIG (RID_SVX_START + 249)
#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 e37c7894e574..8333ce792d9d 100644
--- a/include/sfx2/sfxsids.hrc
+++ b/include/sfx2/sfxsids.hrc
@@ -224,6 +224,7 @@ class SvxZoomItem;
#define SID_VIEW_DATA_SOURCE_BROWSER (SID_SFX_START + 1660)
#define SID_UNPACK (SID_SFX_START + 1662)
// (SID_SFX_START + 1663) used further down
+#define SID_ATTR_TARGETLANG_STR (SID_SFX_START + 1664)
// FREE
#define SID_OUTPUTSTREAM TypedWhichId<SfxUnoAnyItem>(SID_SFX_START + 1666)
#define SID_IMAGE_ORIENTATION (SID_SFX_START + 1667)
diff --git a/include/svtools/deeplcfg.hxx b/include/svtools/deeplcfg.hxx
new file mode 100644
index 000000000000..a943d72d4d7e
--- /dev/null
+++ b/include/svtools/deeplcfg.hxx
@@ -0,0 +1,50 @@
+/* -*- 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 <unotools/configitem.hxx>
+#include <com/sun/star/uno/Sequence.hxx>
+#include <svtools/svtdllapi.h>
+
+using namespace utl;
+using namespace com::sun::star::uno;
+
+struct DeeplOptions_Impl;
+
+class SVT_DLLPUBLIC SvxDeeplOptions final : public utl::ConfigItem
+{
+public:
+ SvxDeeplOptions();
+ virtual ~SvxDeeplOptions() override;
+
+ virtual void Notify(const css::uno::Sequence<OUString>& _rPropertyNames) override;
+ static SvxDeeplOptions& Get();
+
+ const OUString& getAPIUrl() const;
+ void setAPIUrl(const OUString& rVal);
+
+ const OUString& getAuthKey() const;
+ void setAuthKey(const OUString& rVal);
+
+private:
+ std::unique_ptr<DeeplOptions_Impl> pImpl;
+ void Load(const css::uno::Sequence<OUString>& rPropertyNames);
+ virtual void ImplCommit() override;
+ static const Sequence<OUString>& GetPropertyNames();
+};
diff --git a/include/svx/svxids.hrc b/include/svx/svxids.hrc
index 96122a66bc10..20a2a29ac716 100644
--- a/include/svx/svxids.hrc
+++ b/include/svx/svxids.hrc
@@ -587,7 +587,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 )
-//FREE
+#define SID_FM_TRANSLATE ( SID_SVX_START + 608 )
//FREE
#define SID_FM_DELETEROWS ( SID_SVX_START + 610 )
//FREE
diff --git a/include/vcl/htmltransferable.hxx b/include/vcl/htmltransferable.hxx
new file mode 100644
index 000000000000..2576c7e31bb4
--- /dev/null
+++ b/include/vcl/htmltransferable.hxx
@@ -0,0 +1,51 @@
+/* -*- 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 <com/sun/star/datatransfer/XTransferable.hpp>
+#include <cppuhelper/weak.hxx>
+#include <rtl/ustring.hxx>
+#include <vcl/dllapi.h>
+
+namespace vcl::unohelper
+{
+// Helper class for passing HTML string as XTransferable to TransferableDataHelper object
+class VCL_DLLPUBLIC HtmlTransferable final : public css::datatransfer::XTransferable,
+ public ::cppu::OWeakObject
+{
+private:
+ OString data;
+
+public:
+ HtmlTransferable(OString sData);
+ virtual ~HtmlTransferable() override;
+
+ // css::uno::XInterface
+ css::uno::Any SAL_CALL queryInterface(const css::uno::Type& rType) override;
+ void SAL_CALL acquire() noexcept override { OWeakObject::acquire(); }
+ void SAL_CALL release() noexcept override { OWeakObject::release(); }
+
+ // css::datatransfer::XTransferable
+ css::uno::Any SAL_CALL getTransferData(const css::datatransfer::DataFlavor& aFlavor) override;
+ css::uno::Sequence<css::datatransfer::DataFlavor> SAL_CALL getTransferDataFlavors() override;
+ sal_Bool SAL_CALL isDataFlavorSupported(const css::datatransfer::DataFlavor& aFlavor) override;
+};
+
+} // namespace vcl::unohelper