KTextAddons

translatorengineplugin.cpp
1/*
2 SPDX-FileCopyrightText: 2022-2024 Laurent Montel <montel@kde.org>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#include "translatorengineplugin.h"
8#include <KLocalizedString>
9using namespace TextTranslator;
10
11class TextTranslator::TranslatorEnginePluginPrivate
12{
13public:
14 QString mText;
15 QString mFrom;
16 QString mTo;
17 QString mResult;
18 QString mJsonDebug;
19 bool mHasDebug = false;
20};
21
22TranslatorEnginePlugin::TranslatorEnginePlugin(QObject *parent)
23 : QObject(parent)
24 , d(new TextTranslator::TranslatorEnginePluginPrivate)
25{
26 d->mHasDebug = !qEnvironmentVariableIsEmpty("TRANSLATING_DEBUGGING");
27}
28
29QString TranslatorEnginePlugin::resultTranslate() const
30{
31 return result();
32}
33
34TranslatorEnginePlugin::~TranslatorEnginePlugin() = default;
35
36void TranslatorEnginePlugin::setInputText(const QString &text)
37{
38 d->mText = text;
39}
40
41void TranslatorEnginePlugin::setFrom(const QString &language)
42{
43 if (d->mFrom != language) {
44 d->mFrom = language;
45 Q_EMIT languagesChanged();
46 }
47}
48
49void TranslatorEnginePlugin::setTo(const QString &language)
50{
51 if (d->mTo != language) {
52 d->mTo = language;
53 Q_EMIT languagesChanged();
54 }
55}
56
57void TranslatorEnginePlugin::setResult(const QString &result)
58{
59 d->mResult = result;
60}
61
62void TranslatorEnginePlugin::setJsonDebug(const QString &debug)
63{
64 d->mJsonDebug = debug;
65}
66
67void TranslatorEnginePlugin::clear()
68{
69 d->mResult.clear();
70}
71
72void TranslatorEnginePlugin::appendResult(const QString &result)
73{
74 d->mResult += result;
75}
76
77QString TranslatorEnginePlugin::inputText() const
78{
79 return d->mText;
80}
81
82QString TranslatorEnginePlugin::from() const
83{
84 return d->mFrom;
85}
86
87QString TranslatorEnginePlugin::to() const
88{
89 return d->mTo;
90}
91
92QString TranslatorEnginePlugin::result() const
93{
94 return d->mResult;
95}
96
97QString TranslatorEnginePlugin::jsonDebug() const
98{
99 return d->mJsonDebug;
100}
101
102void TranslatorEnginePlugin::slotError(QNetworkReply::NetworkError error)
103{
104 QString messageError;
106 messageError = i18n("Error: Engine systems have detected suspicious traffic from your computer network. Please try your request again later.");
107 }
108 Q_EMIT translateFailed(messageError);
109}
110
111bool TranslatorEnginePlugin::verifyFromAndToLanguage()
112{
113 if (d->mTo == d->mFrom) {
114 Q_EMIT translateFailed(i18n("You used same language for \'from\' and \'to\' language."));
115 return true;
116 }
117 return false;
118}
119
120bool TranslatorEnginePlugin::hasDebug() const
121{
122 return d->mHasDebug;
123}
124
125QString TranslatorEnginePlugin::languageCode(const QString &langStr)
126{
127 return langStr;
128}
129
130#include "moc_translatorengineplugin.cpp"
QString i18n(const char *text, const TYPE &arg...)
Q_EMITQ_EMIT
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Dec 20 2024 11:49:44 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.