Feature: #102326 - Allow custom translations for Extbase validators

See forge#102326

Description

All validation messages from Extbase validators can now be overwritten using validator options. It is possible to provide either a translation key or a custom message as string.

Extbase validators providing only one validation message can be overwritten by a translation key or message using the validator option message. Validators providing multiple validation messages (e.g. Boolean, NotEmpty or NumberRange) use different validator options keys. In general, translation keys or messages for validators are registered in the validator property translationOptions.

Example with translations

use TYPO3\CMS\Extbase\Annotation as Extbase;

#[Extbase\Validate([
    'validator' => 'NotEmpty',
    'options' => [
        'nullMessage' => 'LLL:EXT:my_extension/Resources/Private/Language/locallang.xlf:validation.myProperty.notNull',
        'emptyMessage' => 'LLL:EXT:my_extension/Resources/Private/Language/locallang.xlf:validation.myProperty.notEmpty',
    ],
])]
protected string $myProperty = '';
Copied!

In this example, translation option keys for the NotEmptyValidator are overwritten for the property $myProperty. The locallang.xlf translation file from the extension my_extension will be used to lookup translations for the newly provided translation key options.

Example with a custom string

use TYPO3\CMS\Extbase\Annotation as Extbase;

#[Extbase\Validate([
    'validator' => 'Float',
    'options' => [
        'message' => 'A custom, non translatable message',
    ],
])]
protected float $myProperty = 0.0;
Copied!

In this example, translation option keys for the FloatValidator are overwritten for the property $myProperty. The message string is shown if validation fails.

Impact

The new validator translation option keys allow developers to define unique validation messages for TYPO3 Extbase validators on validator usage basis. This may result in a better user experience, since validation messages now can refer to the current usage scope (e.g. "The field 'Title' is required" instead of "The given subject was empty.").