diff --git a/docs/guide/en/configuring-rules-via-php-attributes.md b/docs/guide/en/configuring-rules-via-php-attributes.md index 3af222d53..ef04bb795 100644 --- a/docs/guide/en/configuring-rules-via-php-attributes.md +++ b/docs/guide/en/configuring-rules-via-php-attributes.md @@ -74,7 +74,7 @@ final class User > **Note:** [readonly properties] are supported only starting from PHP 8.1. -Error messages may include an `{attribute}` placeholder that is replaced with the name of the property. If you would +Error messages may include `{attribute}` or `{Attribute}` placeholder that is replaced with the name of the property. If you would like the name to be replaced with a custom value, you can specify it using the `Label` attribute: ```php diff --git a/docs/guide/en/customizing-error-messages.md b/docs/guide/en/customizing-error-messages.md index 32ce628bf..1d907a925 100644 --- a/docs/guide/en/customizing-error-messages.md +++ b/docs/guide/en/customizing-error-messages.md @@ -4,7 +4,7 @@ To use a non-default error message, pass a custom message/template when creating `message` option is responsible for storing error message: ```php -new Required(message: '{attribute} is required.'); +new Required(message: '{Attribute} is required.'); ``` Some rules have multiple error messages and are overridden via different corresponding options. @@ -113,13 +113,13 @@ use Yiisoft\Validator\Validator; final class ChangePasswordForm implements AttributeTranslatorProviderInterface { public function __construct( - #[Required(message: '{attribute} обязателен для ввода.')] + #[Required(message: '{Attribute} обязателен для ввода.')] public string $currentPassword = '', #[Length( min: 8, skipOnEmpty: false, - lessThanMinMessage: '{attribute} должен быть сложный, не менее 8 символов.' + lessThanMinMessage: '{Attribute} должен быть сложный, не менее 8 символов.' )] public string $newPassword = '', ) { diff --git a/src/ValidationContext.php b/src/ValidationContext.php index aae942b0f..082e2a384 100644 --- a/src/ValidationContext.php +++ b/src/ValidationContext.php @@ -243,10 +243,9 @@ public function getAttributeLabel(): ?string /** * Get translated attribute name. * - * @return string|null Translated attribute name. `null` if a single value is validated and there is nothing - * to translate. + * @return string Translated attribute name. `value` if a single value is validated and a label is not set. */ - public function getTranslatedAttribute(): ?string + public function getTranslatedAttribute(): string { $label = $this->attributeLabel ?? $this->attribute ?? 'value';