digiKam Developer Documentation: Digikam::DOnlineTranslator Class Reference

| digiKam Developer Documentation Professional Photo Management with the Power of Open Source

Loading...
Searching...
No Matches
Public Types | Signals | Public Member Functions | Static Public Member Functions | Friends | List of all members
Digikam::DOnlineTranslator Class Reference

Provides translation data.

Inheritance diagram for Digikam::DOnlineTranslator:

## Public Types
enum | Engine { Google , Yandex , Bing , Lingva , LibreTranslate }
| Represents online engines.
enum | Language { NoLanguage = -1 , Auto , Afrikaans , Albanian , Amharic , Arabic , Armenian , Azerbaijani , Bashkir , Basque , Belarusian , Bengali , Bosnian , Bulgarian , Cantonese , Catalan , Cebuano , Chichewa , Corsican , Croatian , Czech , Danish , Dutch , English , Esperanto , Estonian , Fijian , Filipino , Finnish , French , Frisian , Galician , Georgian , German , Greek , Gujarati , HaitianCreole , Hausa , Hawaiian , Hebrew , HillMari , Hindi , Hmong , Hungarian , Icelandic , Igbo , Indonesian , Irish , Italian , Japanese , Javanese , Kannada , Kazakh , Khmer , Kinyarwanda , Klingon , KlingonPlqaD , Korean , Kurdish , Kyrgyz , Lao , Latin , Latvian , LevantineArabic , Lithuanian , Luxembourgish , Macedonian , Malagasy , Malay , Malayalam , Maltese , Maori , Marathi , Mari , Mongolian , Myanmar , Nepali , Norwegian , Oriya , Papiamento , Pashto , Persian , Polish , Portuguese , Punjabi , QueretaroOtomi , Romanian , Russian , Samoan , ScotsGaelic , SerbianCyrillic , SerbianLatin , Sesotho , Shona , SimplifiedChinese , Sindhi , Sinhala , Slovak , Slovenian , Somali , Spanish , Sundanese , Swahili , Swedish , Tagalog , Tahitian , Tajik , Tamil , Tatar , Telugu , Thai , Tongan , TraditionalChinese , Turkish , Turkmen , Udmurt , Uighur , Ukrainian , Urdu , Uzbek , Vietnamese , Welsh , Xhosa , Yiddish , Yoruba , YucatecMaya , Zulu }
| Represents all languages for translation.
enum | TranslationError { NoError , ParametersError , NetworkError , ServiceError , ParsingError }
| Indicates all possible error conditions found during the processing of the translation. More...

## Signals
void | signalFinished ()
| Translation finished.

## Public Member Functions
| DOnlineTranslator (QObject *const parent=nullptr)
| Create object.
void | abort ()
| Cancel translation operation (if any).
void | detectLanguage (const QString &text, Engine engine=Google)
| Detect language.
TranslationError | error () const
| Last error.
QString | errorString () const
| Last error string.
bool | isRunning () const
| Check translation progress.
bool | isSourceTranscriptionEnabled () const
| Check if source transcription is enabled.
bool | isSourceTranslitEnabled () const
| Check if source transliteration is enabled.
bool | isTranslationOptionsEnabled () const
| Check if translation options are enabled.
bool | isTranslationTranslitEnabled () const
| Check if translation transliteration is enabled.
void | setEngineApiKey (Engine engine, const QByteArray &apiKey)
| Set api key for engine.
void | setEngineUrl (Engine engine, const QString &url)
| Set the URL engine.
void | setSourceTranscriptionEnabled (bool enable)
| Enable or disable source transcription.
void | setSourceTranslitEnabled (bool enable)
| Enable or disable source transliteration.
void | setTranslationOptionsEnabled (bool enable)
| Enable or disable translation options.
void | setTranslationTranslitEnabled (bool enable)
| Enable or disable translation transliteration.
QString | source () const
| Source text.
Language | sourceLanguage () const
| Source language.
QString | sourceLanguageName () const
| Source language name.
QString | sourceTranscription () const
| Source transcription.
QString | sourceTranslit () const
| Source transliteration.
QJsonDocument | toJson () const
| Converts the object to JSON.
void | translate (const QString &text, Engine engine=Google, Language translationLang=Auto, Language sourceLang=Auto, Language uiLang=Auto)
| Translate text.
QString | translation () const
| Translated text.
Language | translationLanguage () const
| Translation language.
QString | translationLanguageName () const
| Translation language name.
QMap< QString, QVector< DOnlineTranslatorOption > > | translationOptions () const
| Translation options.
QString | translationTranslit () const
| Translation transliteration.

## Static Public Member Functions
static QString | engineName (Engine engine)
| Return the engine literal name.
static QString | fromRFC3066 (Engine engine, const QString &langCodeRFC3066)
| Convert language RFC3066 to supported language code.
static bool | isSupportTranslation (Engine engine, Language lang)
| Check if transliteration is supported.
static Language | language (const QLocale &locale)
| Language.
static Language | language (const QString &langCode)
| Returns general language code.
static QString | languageCode (Language lang)
| Language code.
static QString | languageName (Language lang)
| Language name.
static QStringList | supportedRFC3066 (Engine engine)
| Return a list of all supported language in RFC3066.

## Friends
class | DOnlineTts

## Member Enumeration Documentation

## ◆ TranslationError

enum Digikam::DOnlineTranslator::TranslationError

Enumerator
NoError | No error condition.
ParametersError | Unsupported combination of parameters.
NetworkError | Network error.
ServiceError | Service unavailable or maximum number of requests.
ParsingError | The request could not be parsed (report a bug if you see this)

## Constructor & Destructor Documentation

## ◆ DOnlineTranslator()

Digikam::DOnlineTranslator::DOnlineTranslator | ( | QObject *const | parent = `nullptr` | ) |
| explicit

Constructs an object with empty data and with parent. You can use translate() to send text to object.

Parameters

  parent | the parent object

## Member Function Documentation

## ◆ detectLanguage()

void Digikam::DOnlineTranslator::detectLanguage | ( | const QString & | text,
|  | Engine | engine = `Google`
| ) |  |

Parameters

  text | the text for language detection
  engine | the engine to use

## ◆ error()

DOnlineTranslator::TranslationError Digikam::DOnlineTranslator::error | ( |  | ) | const

Error that was found during the processing of the last translation. If no error was found, returns DOnlineTranslator::NoError. The text of the error can be obtained by errorString().

Returns
  last error

## ◆ errorString()

QString Digikam::DOnlineTranslator::errorString | ( |  | ) | const

A human-readable description of the last translation error that occurred.

Returns
  last error string

## ◆ isRunning()

bool Digikam::DOnlineTranslator::isRunning | ( |  | ) | const

Returns
  `true` when the translation is still processing and has not finished or was aborted yet.

## ◆ isSourceTranscriptionEnabled()

bool Digikam::DOnlineTranslator::isSourceTranscriptionEnabled | ( |  | ) | const

Returns
  `true` if source transcription is enabled

## ◆ isSourceTranslitEnabled()

bool Digikam::DOnlineTranslator::isSourceTranslitEnabled | ( |  | ) | const

Returns
  `true` if source transliteration is enabled

## ◆ isSupportTranslation()

bool Digikam::DOnlineTranslator::isSupportTranslation | ( | Engine | engine,
|  | Language | lang
| ) |  |
| static

Parameters

  engine | the engine to use
  lang | language

Returns
  `true` if the specified engine supports transliteration for specified language

## ◆ isTranslationOptionsEnabled()

bool Digikam::DOnlineTranslator::isTranslationOptionsEnabled | ( |  | ) | const

Returns
  `true` if translation options are enabled

See also
  DOnlineTranslatorOption

## ◆ isTranslationTranslitEnabled()

bool Digikam::DOnlineTranslator::isTranslationTranslitEnabled | ( |  | ) | const

Returns
  `true` if translation transliteration is enabled

## ◆ language() [1/2]

DOnlineTranslator::Language Digikam::DOnlineTranslator::language | ( | const QLocale & | locale | ) |
| static

Parameters

  locale | the locale to use

Returns
  language

## ◆ language() [2/2]

DOnlineTranslator::Language Digikam::DOnlineTranslator::language | ( | const QString & | langCode | ) |
| static

Parameters

  langCode | code

Returns
  language

## ◆ languageCode()

QString Digikam::DOnlineTranslator::languageCode | ( | Language | lang | ) |
| static

Parameters

  lang | language

Returns
  language code

## ◆ languageName()

QString Digikam::DOnlineTranslator::languageName | ( | Language | lang | ) |
| static

Parameters

  lang | language

Returns
  language name

## ◆ setEngineApiKey()

void Digikam::DOnlineTranslator::setEngineApiKey | ( | Engine | engine,
|  | const QByteArray & | apiKey
| ) |  |

Affects only LibreTranslate.

Parameters

  engine | the engine to use
  apiKey | your key for this particular instance

## ◆ setEngineUrl()

void Digikam::DOnlineTranslator::setEngineUrl | ( | Engine | engine,
|  | const QString & | url
| ) |  |

Only affects LibreTranslate and Lingva because these engines have multiple instances. You need to call this function to specify the URL of an instance for them.

Parameters

  engine | the engine to use
  url | engine url

## ◆ setSourceTranscriptionEnabled()

void Digikam::DOnlineTranslator::setSourceTranscriptionEnabled | ( | bool | enable | ) |

Parameters

  enable | whether to enable source transcription

## ◆ setSourceTranslitEnabled()

void Digikam::DOnlineTranslator::setSourceTranslitEnabled | ( | bool | enable | ) |

Parameters

  enable | whether to enable source transliteration

## ◆ setTranslationOptionsEnabled()

void Digikam::DOnlineTranslator::setTranslationOptionsEnabled | ( | bool | enable | ) |

Parameters

  enable | whether to enable translation options

See also
  DOnlineTranslatorOption

## ◆ setTranslationTranslitEnabled()

void Digikam::DOnlineTranslator::setTranslationTranslitEnabled | ( | bool | enable | ) |

Parameters

  enable | whether to enable translation transliteration

## ◆ signalFinished

void Digikam::DOnlineTranslator::signalFinished | ( |  | ) |
| signal

This signal is emitted when the translation is complete.

## ◆ source()

QString Digikam::DOnlineTranslator::source | ( |  | ) | const

Returns
  source text

## ◆ sourceLanguage()

DOnlineTranslator::Language Digikam::DOnlineTranslator::sourceLanguage | ( |  | ) | const

Returns
  language of the source text

## ◆ sourceLanguageName()

QString Digikam::DOnlineTranslator::sourceLanguageName | ( |  | ) | const

Returns
  language name of the source text

## ◆ sourceTranscription()

QString Digikam::DOnlineTranslator::sourceTranscription | ( |  | ) | const

Returns
  transcription of the source text

## ◆ sourceTranslit()

QString Digikam::DOnlineTranslator::sourceTranslit | ( |  | ) | const

Returns
  transliteration of the source text

## ◆ toJson()

QJsonDocument Digikam::DOnlineTranslator::toJson | ( |  | ) | const

Returns
  JSON representation

## ◆ translate()

void Digikam::DOnlineTranslator::translate | ( | const QString & | text,
|  | Engine | engine = `Google`,
|  | Language | translationLang = `Auto`,
|  | Language | sourceLang = `Auto`,
|  | Language | uiLang = `Auto`
| ) |  |

Parameters

  text | the text to translate
  engine | online engine to use
  translationLang | language to translation
  sourceLang | language of the passed text
  uiLang | ui language to use for display

## ◆ translation()

QString Digikam::DOnlineTranslator::translation | ( |  | ) | const

Returns
  translated text.

## ◆ translationLanguage()

DOnlineTranslator::Language Digikam::DOnlineTranslator::translationLanguage | ( |  | ) | const

Returns
  language of the translated text

## ◆ translationLanguageName()

QString Digikam::DOnlineTranslator::translationLanguageName | ( |  | ) | const

Returns
  language name of the translated text

## ◆ translationOptions()

QMap< QString, QVector< DOnlineTranslatorOption > > Digikam::DOnlineTranslator::translationOptions | ( |  | ) | const

Returns
  QMap whose key represents the type of speech, and the value is a QVector of translation options

See also
  DOnlineTranslatorOption

## ◆ translationTranslit()

QString Digikam::DOnlineTranslator::translationTranslit | ( |  | ) | const

Returns
  transliteration of the translated text