Multilingual Products

Ian Wood profile picture Written by: Ian Wood - Published on: 06 Mar 2018
A global presence in the marketplace means you can sell to pretty much anybody. That is a fantastic opportunity to expand your customer base… but they don’t all speak your language.

There are some who prefer to live on an island and believe if they ventured too far away they’d fall off the edge of the Earth, but it is a smart person who embraces the opportunity to conduct business cross-border, even cross-culture.

To this end, Moltin recognize the need to communicate with those customers a little further afield and with a completely different set of words in their dictionaries. Product translations are the first offering to allow you to do just this.

Building on top of the v2 platform, the initial translations system provides a mechanism to provide names and descriptions of products in up to five languages beyond your default (these are defined in the settings service).

The system may change a little over time but, for now, we want to provide something simple and stripped back. Based on your feedback we expect to improve and refine the translations system.

Adding languages

Before you can use this feature you’ll need to have the languages you wish to translate in the system. To do so send a PUT request to the settings endpoint as detailed below. For more information see the settings service documentation.

  curl -X PUT https://api.moltin.com/v2/settings \
    -H "Authorization: Bearer 0bfcb98e2d903c680775e209cde36a73c5d82000" \ 
    -H "Content-Type: application/json" \
    -d $'{
  "data": {
    "type": "settings",
    "additional_languages": ["es","de"]
  }
}'

This would add Spanish (‘es’) and German (‘de’) language tags to your store.

Creating translations

You have your products in the system already. You can only create translations for the name and description fields via an update to your product; you should send a PUT request along with the X-MOLTIN-LANGUAGE header and the translated strings in the name and description fields.

  curl -X PUT https://api.moltin.com/v2/products/{PRODUCT_ID} \
    -H "Authorization: Bearer 0bfcb98e2d903c680775e209cde36a73c5d82000" \ 
    -H "X-MOLTIN-LANGUAGE: es" \ 
    -H "Content-Type: application/json" \
    -d $'{
  "data": {
    "type": "product",
    "id": "{PRODUCT_ID}",
    "name": "nombre del producto"
    "description": "descripción del producto"
  }
}'

Retrieve translations

OK, you’ve added a translation for our Spanish speaking citizens of the world. We need to be able to show them this instead of our default ‘English’ text. No surprises here, add the header and if that translation exists it will be returned. If the requested language does not have a translation available the default will be returned.

Get a list of products

  curl -X GET https://api.moltin.com/v2/products \
    -H "Authorization: Bearer 0bfcb98e2d903c680775e209cde36a73c5d82000" \ 
    -H "X-MOLTIN-LANGUAGE: es"

Get a single translated product

  curl -X GET https://api.moltin.com/v2/products/{PRODUCT_ID} \
    -H "Authorization: Bearer 0bfcb98e2d903c680775e209cde36a73c5d82000" \ 
    -H "X-MOLTIN-LANGUAGE: es"

Response

In either of the above cases you should expect to see a response body exactly like you get already, but with the name and description fields populated with translated strings.

  {
  "data": {
    "type": "product",
    "id": "6837058c-ae42-46db-b3c6-7f01e0c34b40",
    "name": "nombre del producto",
    "description": "descripción del producto.",
    ...
  }
}

You should hopefully recognize the simplicity of the implementation but we do welcome your input too - please visit the Moltin forum and leave your feedback.

Build something amazing with Moltin