Backend Localization Configuration
The Citeck platform supports server-side localization of error messages.
In a microservice or library, a file with the list of message localizations must be added to resources/ecos/messages in the following format:
{
"id": "test-messages",
"locales": [
"en",
"ru"
],
"messages": {
"label.yes": [
"Yes",
"Да"
],
"label.no": [
"No",
"Нет"
],
"server-error-occurred-with-code": [
"Server error occurred. Error code: {{code}}",
"Произошла ошибка на сервере. Код ошибки: {{code}}"
]
}
}
The message localization must be listed in the same order as specified in locales.
Parameters can be substituted into the text in the following format:
{{param}}
The I18nRuntimeException exception has been added to handle localized errors. For example:
throw I18nRuntimeException.create()
.messageKey("label.yes")
.build()
Example with parameter substitution:
throw I18nRuntimeException.create()
.messageKey("server-error-occurred-with-code")
.messageArgs(
mapOf(
"code" to 500
)
)
.build()
When handling such an exception, the English localization is always written to the logs. If no localization is found, the message key will be used. The error text returned to the client is based on the localization in the request context.