ITranslation is a simple translation client which can use different Translation Services Translation Service.

File information


Functions Functions to initialize
Classes ITranslation

Examples Code Example


Functions to initialize

extern "C" ITranslation * CreateIBMTranslation(class IIoMux* const iomux,
    class ISocketProvider* const tcpSocketProvider,
    class ISocketProvider* const tlsSocketProvider,
    class ISocketContext* socketContext,
    class UTranslation* const user,
    class IInstanceLog* const log,
    const char* endpoint_url,
    const char* resource_name,
    const char* api_key);
Create an ITranslation instance.


IIoMux * const iomuxThe iomux instance needed for socket communication.
ISocketProvider * const tcpSocketProviderA socket provider to create a TCP socket.
ISocketProvider * const tlsSocketProviderA socket provider to create a TLS socket.
ISocketContext * const socketContextAn optional socketContext which can be used for the socket which is created by the httpclient. You can disable sending of a client certificate with this socketContext or send a specific own client certificate.
UTranslation * const userAn UTranslation instance to receive the callbakcs from ITranslation.
IInstanceLog * const logThe log instance for logging.
const char* endpoint_urlThe URL of the IBM Server for the requests.
const char* resource_nameThe Resource on the IBM Server for the request.
const char* api_keyThe API Key to access the translation service.

Return Value

The ITranslation instance created. Must be deleted if no longer used.



class ITranslation {
    virtual ~ITranslation() {};
    virtual void Translate(class TranslationObject* translationObject) = 0;
    virtual void Shutdown() = 0;

This is the main class of the Translation module. The translation-module is using an external webservice from IBM to translate the texts. Therefore it requires informations from the IBM Cloud Language Translator (IBM Watson Translator).

Public functions

Translate the given text to the given language. For supported languages have a look to the IBM documentation.


class TranslationObject* translationObjectThe translation object, which should be translated.


UTranslation::TranslationCompleted(const char* translation) will be called after the data has been translated.


There should be only one translation requested at a time. It's not supported to translate two texts with the same instance on the same time.


class UTranslation {
    virtual void TranslationConnected(const ITranslation* translator) = 0;
    virtual void TranslationCompleted(const ITranslation* translator, class TranslationObject* translationObject) = 0;
    virtual void TranslationShutdown(const ITranslation* translator) = 0;
    ~UTranslation() {}

This class is for receiving callbacks from the ITranslation. You must pass as subclass of UTranslation to an ITranslation as user.

Will be called after the translation has been completed.


ITranslation * const httpClientThe calling ITranslation instance.
class TranslationObject* translationObjectThe translation object with the translated text
Will be called after the translation has been closed.


ITranslation * const httpClientThe calling ITranslation instance.


class TranslationObject : public istd::listElement {
    const char* getSource_Language() { return source_language; };
    const char* getTarget_Language() { return target_language; };
    const char* getTranslation() { return translation; };
    TranslationObject(const char* text, const char* source_language, const char* target_language);
This class is for creating an Object which handles the translation
Constructor for a translation object.


const char* textThe text, which should be translated.
const char* source_languageThe source language
const char* target_languageThe target language
Readout the source language.

Return Value

Returns the target language.
Readout the target language.

Return Value

Returns the target language.
Readout the Translation.

Return Value

Returns the translated text.

Code Example

app::app(IIoMux * iomux)
    : iomux(iomux)
    // you can optionally create a socketContext, if you e.g. want to disable sending of a client certificate
    class ISocketContext * socketContext = aTlsSocketProvider->CreateSocketContext(this);
    // create the translation instance
    this->translation = ITranslation::Create(iomux, service->tcpSocketProvider, service->tlsSocketProvider, socketContext, this, this, "", "/instances/*****************", "******************");
    this->translation->Translate(new class TranslationObject("Hallo Welt", "de", "en"));

void STT::TranslationCompleted(const ITranslation* translator, const char* translation) {
    printf("Translation: %s", translation);

void app::TranslationShutdown(const ITranslation* translator)
    delete this->translation;