From 8eab800e193937e93ade1fabe5697675bb4fb940 Mon Sep 17 00:00:00 2001 From: Marc Becker Date: Tue, 21 Jan 2025 16:11:29 +0100 Subject: [PATCH] CAP Java Validation Error Translations --- java/event-handlers/indicating-errors.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/java/event-handlers/indicating-errors.md b/java/event-handlers/indicating-errors.md index 057c445b7..5302b1895 100644 --- a/java/event-handlers/indicating-errors.md +++ b/java/event-handlers/indicating-errors.md @@ -122,6 +122,12 @@ messages.warn("my.message.key", paramNumber); throw new ServiceException(ErrorStatuses.BAD_REQUEST, "my.message.key", paramNumber, originalException); ``` +### Out-of-the-box Translations for Validation Error Messages + +CAP Java provides out-of-the-box translation for error messages that originate from input validation annotations such as `@assert...` or `@mandatory` and security annotations `@requires` and `@restrict`. +The error messages are optimized for UI scenarios and avoid any technical references to entity names or element names. Message targets are used where appropriate to allow the UI to show the error message next to the affected UI element. +You can enable these translated error messages by setting [cds.errors.defaultTranslations.enabled: true](../../java/developing-applications/properties#cds-errors-default-translations-enabled). + ### Exporting the Default Messages As of CAP Java 1.10.0, you can extract the available default messages as a resource bundle file for further processing (for example, translation). Therefore, the delivery artifact [cds-services-utils](https://search.maven.org/artifact/com.sap.cds/cds-services-utils) contains a resource bundle `cds-messages-template.properties` with all available error codes and default messages. Application developers can use this template to customize error messages thrown by the CAP Java SDK in the application.