Issue Feature Closed

#102326Allow custom translation keys for extbase validators

Torben Hansen 11/06/23, 13:40 updated 07/04/24, 13:16

Description

Extbase validators do currently use hardcoded translation keys to output possible validation messages. Those translation keys can globally be overwritten using a custom localization file, but it is not possible to provide individual translation keys for validation errors in a given context (e.g. property or dedicated validator call).

There is a workaround (https://stackoverflow.com/a/40400270/1744743) out there, which uses fluid and the given error codes of the extbase validators. This works fine, but I think extbase should provide something out of the box in order to define translation keys in code as shown below:

    #[Validate([
        'validator' => 'NotEmpty',
        'options' => [
            'nullTranslateKey' => 'validation.title.notNull',
            'emptyTranslateKey' => 'validation.title.notEmpty',
            'extensionName' => 'my_extension'
        ],
    ])]
    protected string $title = '';

Reviews 6