Skip to content

Connecting an External Translation Service#

Hub-repo does not perform any translations by its own, instead, when enabled, it outsources this task to an external service. The simple and asynchronous approach allows it to install any kind of translation process behind, either machine based or manually driven.

You have to:

  • Implement a service with a specific endpoint to receive the translation request
  • This implementation must understand the requested translation information provided in a well-defined JSON object structure
  • This implementation must be able to send back the translation to the repo translation callback endpoint as well-defined JSON object structure

When and What#

Although the translation itself is not performed by hub-repo, it will trigger a translation when it detects missing translations or changed property values during creation or updating a DCAT resources metadata. The custom translation service is not enforced to provide all tranlations at once. But to reduce the load, it is recommended to limit the updates, preferable only once when all possible translations are finished.

Configuration#

You can configure the hub repo for a custom translation service via the environment variable PIVEAU_TRANSLATION_SERVICE

{
  "enable": true,
  "accepted_languages": [
    "en","bg","hr","cs","da","nl","et","fi","fr","el","hu","ga","it","lv","lt","mt","pl","pt","ro","sk","sl","es","sv","de","uk"
  ],
  "translation_service_url": "http://my-translation-service:8080/request-translation",
  "callback_url": "http://piveau-hub-repo:8080/tranlations"
}

Implementation#

The whole process is very simple and completely asynchronous. The translation can be sent back at any time, there are no timeouts. There is also no callback for failures.

sequenceDiagram
    participant A as piveau-hub-repo
    participant B as Custom Translation Service
    A ->> B: request translations
    B -->> A: accepted
    B -) A: callback translation results 
    A -->> B: accepted

Translation Request from repo#

The service must provide an http (or https) endpoint receiving a POST request with content type application/json and a JSON structure following this schema. The main parts of it are the resource id, some general/additional data, a dictionary of requested translations, and finally the callback information. The additional data can be used, but MUST be kept in the callback.

Example Request

{
  "id": "dataset1",
  "data": {
    "catalogueId": "catalogue1",
    "defaultLanguage": "en"
  },
  "dict": {
    "http://piveau.io/set/data/dataset1": {
      "http://purl.org/dc/terms/title": {
        "value": "My Dataset Number One",
        "sourceLanguage": "en",
        "targetLanguages": [
          "de",
          "fr",
          "es"
        ]
      }
    },
    .
    .
    .
  },
  "callback": {
    "url": "http://piveau-hub-repo:8080/tranlations",
    "method": "PUT",
    "headers": {
      "X-API-Key": "anyKey"
    }
  }
}

The dictionary contains the triples to be translated, whereas the subject and the predicate URI references are used as keys of a nested JSON structure, finally containing the literal object value in the property value.

Translation callback#

The service should send the translation results to the hub repo callback endpoint with content type application/json and a JSON structure following this schema. It is quite similar structured as the request, but without the callback object and an enriched dictionary.

Example Callback

{
  "id": "dataset1",
  "data": {
    "catalogueId": "catalogue1",
    "defaultLanguage": "en"
  },
  "dict": {
    "http://piveau.io/set/data/dataset1": {
      "http://purl.org/dc/terms/title": {
        "value": "My Dataset Number One",
        "sourceLanguage": "en",
        "targetLanguages": [
          "de",
          "fr",
          "es"
        ],
        "translations": {
          "en": "Mein Datensatz Nummer Eins",
          "fr": "Mon jeu de données numéro un",
          "es": -1
        }
      }
    },
    .
    .
    .
  }
}

Language translations can contain an integer instead of the translated text to indicate some problems. The repo will not yet evaluate them, but may be respect them in later versions.

Translation Metadata#

The repo stores information about the current translation status of a DCAT resource as part of the catalogue record. In case of a catalogue, it will be stored directly in the catalogue's metadata (under further investigation). The following properties are used:

Namespace

Prefix URI
edp: http://europeandataportal.eu/ns/voc#

Properties

Property Type Description
edp:originalLanguage Literal The original langue to translate from
edp:transStatus Resource The actual current status of the translation
edp:transIssued Typed Literal (xsd:dateTime) Timestamp of last translation request sent
edp:transReceived Typed Literal (xsd:dateTime) Timestamp of last translation result received

Status values

Value Description
edp:TransCompleted A translation has been received
edp:TransInProcess A request has been sent and no translations came back yet