How can I load the correct translated message in a response?

I’m working on returning translated messages in a response, but I’m running into an issue.

Currently, when the Front-end calls a REST process, the response always shows the Dutch translation. (In the architect, we have both English and Dutch translations in the returned error.) For example, here’s a simplified version of the response we get (Error2 is the default error with a ToString() function):

{
  "success": true,
  "error": {
    "Message": "Message11874370"
  },
  "response": {
    "error2": ".......... Controleer de ...... en probeer het opnieuw of neem contact op met de klantenservice."
  },
  "httpcode": 200
}

We tested this in the expression debugger. I tried the following expressions:

messages:loadtranslated("Message11874370").tostring()

This does not show the translated message.

messages:load("Message11874370").tostring()

This works, but only for the current language, not for translations.

What I want to achieve is that when the Front-end is set to English, the response of the REST process is also in English.

Has anyone solved this before, or is there a specific function/approach to ensure the correct translation is returned in the response?

Hi Daniel,

To have control over the translations - i.e. the error message, you can send your REST request with this custom header:

“Preferred-culture” - value is the culture you want Messages translated to. (nl-NL,en-US, en-GB, etc.)

Be aware, that to get the translation in the requested culture, the Message should have translation in that language.

By default, if you do not specify the “Preferred-culture” custom header, the response would be in the default language for the application. (I believe the default language for the application is defined in the webconfig and the default value is the First value of the .languages key)