Translations

Descriptive fields — such as names or descriptions — can be localized and translated into multiple languages.

In the Emporix Commerce Engine, localized fields are stored in the form of String-String maps, where the keys are language codes and the values are the translations.

How to create a localized object in a specific language

To create an object where field values are specified in one language, you need to call a POST endpoint for a specific resource with the Content-Language header set to the language's IETF BCP 47 tag.

Here's an example on how to create a measurement unit with its name in German:

curl -i -X POST \
  'https://api.emporix.io/unit-handling/{tenant}/units' \
  -H 'Authorization: Bearer <YOUR_TOKEN_HERE>' \
  -H 'Content-Language: de' \
  -H 'Content-Type: application/json' \
  -d '{
    "code": "kg",
    "name": "kilogram",
    "type": "mass",
    "baseUnit": true,
    "symbol": "kg",
    "factor": 1
  }'

How to create a localized object in multiple languages

To create an object where field values are translated to multiple languages, you need to call a POST endpoint for a specific resource with the Content-Language header set to *.

Here's an example on how to create a measurement unit with its name in multiple languages:

curl -i -X POST \
  'https://api.emporix.io/unit-handling/{tenant}/units' \
  -H 'Authorization: Bearer <YOUR_TOKEN_HERE>' \
  -H 'Content-Language: *' \
  -H 'Content-Type: application/json' \
  -d '{
    "code": "kg",
    "name": "kilogram",
    "type": "mass",
    "baseUnit": true,
    "symbol": "kg",
    "factor": 1
  }'

How to retrieve a localized object in a specific language

To retrieve localized fields in one language, you need to call a GET endpoint for a specific resource with the Accept-Language header set to the language's IETF BCP 47 tag.

Here's an example on how to retrieve a product's localized fields in German:

curl -i -X GET \
  'https://api.emporix.io/product/{tenant}/products/{productId}?fields=name%2Ccode&expand=string&rawValue=true' \
  -H 'Accept-Language: de' \
  -H 'Authorization: Bearer <YOUR_TOKEN_HERE>'

How to retrieve a localized object in all available languages

To retrieve localized fields in all available languages, you need to call a GET endpoint for a specific resource with the Accept-Language header set to *.

Here's an example on how to retrieve a product's localized fields in all available languages:

curl -i -X GET \
  'https://api.emporix.io/product/{tenant}/products/{productId}?fields=name%2Ccode&expand=string&rawValue=true' \
  -H 'Accept-Language: *' \
  -H 'Authorization: Bearer <YOUR_TOKEN_HERE>'

How to add localized fields to an existing object

To add translations to an existing object's localizable fields, you need to call a PUT or a PATCH endpoint for a specific resource with the Content-Language header set to *.

Here's an example on how to add translations to a measurement unit's name:

curl -i -X PUT \
  'https://api.emporix.io/unit-handling/{tenant}/units/{unitCode}' \
  -H 'Authorization: Bearer <YOUR_TOKEN_HERE>' \
  -H 'Content-Language: fr' \
  -H 'Content-Type: application/json' \
  -d '{
    "code": "kg",
    "name": {
      "de": "Kilogramm",
      "en": "kilogram",
      "pl": "kilogram",
      "fr": "kilogramme"
    },
    "type": "mass",
    "baseUnit": true,
    "factor": 1,
    "metadata": {
      "version": 1
    }
  }

Last updated

Was this helpful?