KTextAddons

translation.h
1/*
2 SPDX-FileCopyrightText: 2023-2025 Laurent Montel <montel@kde.org>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5
6 Based on translateLocally code
7*/
8
9#pragma once
10#include "libbergamot_export.h"
11#include <QMetaType>
12#include <QString>
13#include <memory>
14
15namespace slimt
16{
17class Response;
18}
19
20/**
21 * Wrapper around a translation response from the bergamot service. Hides that
22 * interface from the rest of the Qt code, and provides utility functions to
23 * access alignment information with character offsets instead of byte offsets.
24 */
25class LIBBERGAMOT_EXPORT Translation
26{
27public:
29 Translation(slimt::Response &&response);
30
31 /**
32 * Bool operator to check whether this is an initialised translation or just
33 * an empty object.
34 */
35 inline operator bool() const
36 {
37 return !!mResponse;
38 }
39
40 /**
41 * Translation result
42 */
43 [[nodiscard]] QString translation() const;
44
45private:
46 // Note: I would have liked unique_ptr, but that does not go well with
47 // passing Translation objects through Qt signals/slots.
48 std::shared_ptr<slimt::Response> mResponse;
49};
50
51Q_DECLARE_METATYPE(Translation)
Wrapper around a translation response from the bergamot service.
Definition translation.h:26
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Jan 3 2025 11:46:56 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.