How to translate a custom Constraint message? I have a custom constraint in the Allow a content type only once (Only One) module that is working and is defined as:

&lt;?php

namespace Drupal\onlyone\Plugin\Validation\Constraint;

use Symfony\Component\Validator\Constraint;

/**
 * Checks that Only One node of locked languages exists.
 *
 * @Constraint(
 *   id = "LockedLanguages",
 *   label = @Translation("Locked Languages Constraint", context = "Validation"),
 *   type = { "entity" }
 * )
 */
class LockedLanguagesConstraint extends Constraint {

  /**
   * Message shown when a node of a locked language exists on a content type.
   *
   * @var string
   */
  public $nodeExists = "The content type %content_type is configured to have Only One node per language but the node &lt;a href=':href'&gt;@title&lt;/a&gt; exists for the %language language.";

}


And I want to be able to translate the message, the problem is that you can't use the t() function in the property definition. How can I accomplish this?
The constraint system is one of the few places where string literals aren't directly wrapped in t(). One reason for this is probably because the variables which form the "context" and string replacements for the messages aren't directly available when defining the constraint. @see \Drupal\Core\Validation\DrupalTranslator.

So the answer is: core does this for you. You can see exactly where this happens in: \Drupal\Core\TypedData\Validation\ExecutionContext::addViolation.