API: Importing translations

You can use Haiilo's API to add custom translations. While you can always edit the default translations directly on the platform, using the API is required for adding translations for, e.g., new profile fields you've created yourself.

Also, in case you are using a language for which Haiilo doesn't provide default translations, you have to provide the translations yourself in bulk. Instead of manually inputting them in the platform settings, you can utilize the API to make the task easier for you.

To make calls to the Haiilo API, you need to authenticate first. You can find detailed information about authenticating and using the API here. Also, to perform the following API steps, please make sure to sign in as a superadmin.

List all activated languages

You can view your activated languages in the platform under Administration > Languages, or with the below API call.

  1. Make a GET request to the endpoint /api/languages.

The response should look like below if you've activated English, German, and French:

[
    {
        "language": "DE",
        "active": true,
        "defaultLanguage": false
    },
    {
        "language": "EN",
        "active": true,
        "defaultLanguage": true
    },
    {
        "language": "FR",
        "active": true,
        "defaultLanguage": false
    }
]

Activate a language

You can activate languages in the platform from Administration > Languages, or with the below API call.

  1. Start a new request
  2. Enter the below in the request body
    {
    "active": true
    }
  3. Make a PUT request to the endpoint /api/languages/<language> where <language> is the language tag in uppercase letters of the specific language you want to activate. E.g., ES for Spanish

Add a translation

The following steps depend on whether you're creating a completely new translation or replacing an earlier translation.

Create a new translation

  1. Start a new request
  2. Enter the below in the request body
    {
    "value":"<translation>",
    "bundle":"<bundle>"
    }
  3. Replace the placeholders as follows:
    • <language>: The language tag in lowercase letters of the specific language you want to edit. E.g., en for English
    • <language_key>: The name of the language key that you want to customize. E.g., a new user profile field called roomnumber could have the key USER.ROOMNUMBER
    • <translation>: The new translation you want to add for the language key. E.g., for the roomnumber field in English, we might select "Room number" as the translation.
    • <bundle>: Either "frontend" or "backend"
  4. Make a POST request to the endpoint /web/i18n/overrides/<language>/translations/<language_key> to import a new translation
  5. Repeat for the other bundle, if necessary.

Replace a translation

  1. Start a new request
  2. Enter the below in the request body
    {
    "value":"<translation>",
    "bundle":"<bundle>"
    }
  3. Replace the placeholders (view above for placeholder definitions)
  4. Make a PUT request to the endpoint /web/i18n/overrides/<language>/translations/<language_key> to customize an existing translation

Delete a translation

  1. Replace the placeholders (view above for placeholder definitions)
  2. Make a DELETE request to the endpoint /web/i18n/overrides/<language>/translations/<bundle>/<language_key> to delete an existing translation

List your custom translations

  1. Make a GET request to the endpoint /web/i18n/overrides/public/<language>/translations to see your existing translations
  2. Replace <language> with the language tag in lowercase letters of the specific language you want to see the translations for. E.g., en for English 

The response shows the language keys for which you've added custom translations, either via the API or in the platform.

Was this article helpful?