Internationalization

i18n: internationalization of screen messages

Nick provides the possibility retrieve screen messages in a different language. To achieve that, the REST API requires to use the Accept-Language HTTP header passing as the value the code of the required language.

Using this option we can get the content-type titles translated:

GET /@types HTTP/1.1
Accept: application/json
Accept-Language: nl
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJhZG1pbiIsImZ1bGxuYW1lIjoiQWRtaW4iLCJpYXQiOjE2NDkzMTI0NDl9.RS1Ny_r0v7vIylFfK6q0JVJrkiDuTOh9iG9IL8xbzAk

Or use the client directly:

import { Client } from '@robgietema/nick';

const cli = Client.initialize({ apiPath: 'http://localhost:8080' });
const login = await cli.login({ username: 'admin', password: 'admin' });

const { data } = await cli.getTypes({
  token: login.data.token,
  headers: {
    'Accept-Language': 'nl',
  },
});

And the response:

HTTP/1.1 200 OK
Content-Type: application/json

[
  {
    "@id": "http://localhost:8080/@types/File",
    "addable": true,
    "title": "Bestand"
  },
  {
    "@id": "http://localhost:8080/@types/Folder",
    "addable": true,
    "title": "Map"
  },
  {
    "@id": "http://localhost:8080/@types/Image",
    "addable": true,
    "title": "Afbeelding"
  },
  {
    "@id": "http://localhost:8080/@types/Page",
    "addable": true,
    "title": "Pagina"
  },
  {
    "@id": "http://localhost:8080/@types/Site",
    "addable": false,
    "title": "Site"
  }
]