Validation translation example does not work for production

Im trying to add translations for my form validations. Im doing this like i the example:

the example uses the validator constructor names to generate message keys like so: let key = validationError.${};

This sadly does not work for production because the validator classes get minified in the build process and thus receive a random cryptic name.

I can see 2 solutions that i really want to avoid

  1. I dont minify my frontend for prod.
  2. I Remove backend validation completely and add frontend validators like so: new NotNull({message: 'validationErrors.NotNull'})

Both ways dont seem viable to me, so surely there must be a better way to do this right?

That seems like an oversight in the API’s design, but maybe someone from the team can provide more insight. In general a bit weird that interpolateMessageCallback does not provide you with a validation message key, and you have to construct it yourself from the validator instance.

Possible workaround: import the validator classes you use, add a property with the validator name to them (e.g. (NotNull as any).validatorName = 'NotNull'), and then access it with validator.constructor.validatorName.

Yea i would expect something like or maybe a setting for disabling autogenerated frontend validators.

Your workaround seems pretty solid. I’ll probably end up doing it that way. Thanks