How do I override the $message value of the UniqueFieldConstraint class?
The message is hard-coded into UniqueFieldConstraint. It's a public property, so there may be a way to set it that I don't know about. However, another way to go about it is to extend UniqueFieldConstraint, set your own message, and tell the system to use your class instead of the original.


Extend the class:

namespace Drupal\[MODULE]\Plugin\Validation\Constraint;

use Drupal\Core\Validation\Plugin\Validation\Constraint\UniqueFieldConstraint;

class [MODULE]UniqueFieldConstraint extends UniqueFieldConstraint {
  public $message = 'Something about an @entity_type with a @field_name and value of %value.';
}

Implement hook_validation_constraint_alter() to swap out the existing constraint for yours:

function [MODULE]_validation_constraint_alter(array &amp;$definitions) {
  $definitions['UniqueField']['class'] = '\\Drupal\\[MODULE]\\Validator\\Constraints\\[MODULE]UniqueFieldConstraint';
}



Note that [MODULE] should be swapped out with the appropriate value, and the class should be placed in the appropriate folder for the given namespace.

Update: Or, as 4k4 mentioned, you can add @Constraint annotation to the  constraint above, creating a new constraint. This new constraint can then be explicitly attached to whatever it is that needs constraining.

Which method to use will depend on whether you want to override the UniqueFieldConstraint message any time it is called (the original method I outlined) or whether you want to explicitly attach the constraint to specific items (4k4's method).