Skip to content

Commit

Permalink
Sync attribute translations (#718)
Browse files Browse the repository at this point in the history
* Revert "Revert "Change type of `$escape` argument in `Error::getValuePath()` from `bool|string|null` to `string|null`""

This reverts commit c5a2b49.

* Update attribute translations

* Sync with master

* WIP

* Image rule

* Apply fixes from StyleCI

* Compare

* Number + changelog entry

* Apply fixes from StyleCI

* At least

* Boolean value

* Apply fixes from StyleCI

* True value

* Apply fixes from StyleCI

* Each

* Nested

* OneOf

* unique iterable

* Fix mutant

* Fix mutant 2

* Fix mutant 3

---------

Co-authored-by: StyleCI Bot <[email protected]>
  • Loading branch information
arogachev and StyleCIBot authored Jul 28, 2024
1 parent 598b14a commit 23a9b0c
Show file tree
Hide file tree
Showing 52 changed files with 454 additions and 413 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## 2.0.0 under development

- New #630: Include attribute name in error messages when it's present (@dood-)
- New #630, #718: Include attribute name in error messages when it's present (@dood-, @arogachev)
- New #646, #653: Add `DateTime` rule (@pamparam83)
- New #615: Add the `Each::PARAMETER_EACH_KEY` validation context parameter that available during `Each` rule handling
and containing the current key (@dood-)
Expand Down
64 changes: 43 additions & 21 deletions messages/ru/yii-validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Yiisoft\Validator\Rule\Equal;
use Yiisoft\Validator\Rule\GreaterThan;
use Yiisoft\Validator\Rule\GreaterThanOrEqual;
use Yiisoft\Validator\Rule\Image\Image;
use Yiisoft\Validator\Rule\In;
use Yiisoft\Validator\Rule\Integer;
use Yiisoft\Validator\Rule\Ip;
Expand All @@ -36,11 +37,8 @@
// Used in single rule

/** @see AtLeast */
'At least {min, number} {min, plural, one{property} other{properties}} from this list must be filled' => 'Как ' .
'минимум {min, number}' .
'{min, plural, one{свойство} few{свойства} many{свойства} other{свойства}} из этого списка ' .
'{min, plural, one{должен} few{должны} many{должны} other{должны}} быть ' .
'заполнены: {properties}.',
'At least {min, number} {min, plural, one{property} other{properties}} from this list must be filled for {property}: {properties}' =>
'Как минимум {min, number} {min, plural, one{свойство} few{свойства} many{свойства} other{свойства}} из этого списка {min, plural, one{должен} few{должны} many{должны} other{должны}} быть заполнены для {property}: {properties}.',
/** @see BooleanValue */
'{Property} must be either "{true}" or "{false}".' => '{Property} должно быть «{true}» или «{false}».',
/** @see Count */
Expand All @@ -50,7 +48,8 @@
'{Property} must contain exactly {exactly, number} {exactly, plural, one{item} other{items}}.' => '{Property} должно содержать ровно {exactly, number} {exactly, plural, one{элемент} few{элемента} many{элементов} other{элементов}}.',
/** @see Each */
'{Property} must be array or iterable.' => '{Property} должно быть массивом или иметь псевдотип iterable.',
'Every iterable key must have an integer or a string type.' => 'Ключ должен иметь тип integer или string.',
'Every iterable key of {property} must have an integer or a string type.' =>
'Ключ {property} должен иметь тип integer или string.',
/** @see Email */
'{Property} is not a valid email address.' => '{Property} не является правильным адресом электронной почты.',
/** @see In */
Expand All @@ -75,13 +74,14 @@
'{Property} must contain at most {max, number} {max, plural, one{character} other{characters}}.' => '{Property} должно содержать не более {max, number} {max, plural, one{символа} few{символов} many{символов} other{символов}}.',
'{Property} must contain exactly {exactly, number} {exactly, plural, one{character} other{characters}}.' => '{Property} должно содержать ровно {exactly, number} {exactly, plural, one{символ} few{символа} many{символов} other{символов}}.',
/** @see Nested */
'Nested rule without rules can be used for objects only.' => 'Правило Nested без указания правил может использоваться только для объектов.',
'An object data set data can only have an array type.' => 'Данные в объекте должны быть массивом.',
'Property "{path}" is not found.' => 'Свойство «{path}» не найдено.',
'Nested rule without rules requires {property} to be an object.' => 'При правиле Nested без указания правил {property} должно быть объектом,',
'An object data set data for {property} can only have an array type.' => 'Данные в объекте для {property} должны быть массивом.',
'Property "{path}" is not found in {property}.' => 'Свойство «{path}» не найдено в {property}.',
/** @see Number */
'{Property} must be a number.' => '{Property} должно быть числом.',
/** @see OneOf */
'Exactly 1 property from this list must be filled: {properties}.' => 'Ровно 1 свойство из этого списка должно быть заполнен: {properties}.',
'Exactly 1 property from this list must be filled for {property}: {properties}.' =>
'Ровно 1 свойство из этого списка должно быть заполнено в {property}: {properties}.',
/** @see Regex */
'{Property} is invalid.' => 'Значение неверно.',
/** @see Required */
Expand All @@ -107,7 +107,8 @@
* @see BooleanValue
* @see TrueValue
*/
'The allowed types are integer, float, string, boolean. {type} given.' => 'Разрешённые типы: integer, float, string, boolean. Передан {type}.',
'The allowed types for {property} are integer, float, string, boolean. {type} given.' =>
'Разрешённые типы для {property}: integer, float, string, boolean. Передан {type}.',
/**
* @see Compare
* @see Equal
Expand All @@ -117,8 +118,10 @@
* @see LessThanOrEqual
* @see NotEqual
*/
'The allowed types are integer, float, string, boolean, null and object implementing \Stringable or \DateTimeInterface.' => 'Разрешённые типы: integer, float, string, boolean, null и объект, реализующий интерфейс \Stringable или \DateTimeInterface.',
'The property value returned from a custom data set must have one of the following types: integer, float, string, boolean, null or an object implementing \Stringable interface or \DateTimeInterface.' => 'Значение, получаемое из пользовательского набора данных, должно иметь один из следующих типов: integer, float, string, bool, null или объект, реализующий интерфейс \Stringable или \DateTimeInterface.',
'The allowed types for {property} are integer, float, string, boolean, null and object implementing \Stringable or \DateTimeInterface.' =>
'Разрешённые типы для {property}: integer, float, string, boolean, null и объект, реализующий интерфейс \Stringable или \DateTimeInterface.',
'{Property} returned from a custom data set must have one of the following types: integer, float, string, boolean, null or an object implementing \Stringable interface or \DateTimeInterface.' =>
'{Property}, получаемое из пользовательского набора данных, должно иметь один из следующих типов: integer, float, string, bool, null или объект, реализующий интерфейс \Stringable или \DateTimeInterface.',
'{Property} must be equal to "{targetValueOrProperty}".' => '{Property} должно быть равно «{targetValueOrProperty}».',
'{Property} must be strictly equal to "{targetValueOrProperty}".' => '{Property} должно быть строго равно «{targetValueOrProperty}».',
'{Property} must not be equal to "{targetValueOrProperty}".' => '{Property} не должно быть равно «{targetValueOrProperty}».',
Expand All @@ -141,7 +144,7 @@
* @see Number
* @see Integer
*/
'The allowed types are integer, float and string.' => 'Разрешённые типы: integer, float и string.',
'The allowed types for {property} are integer, float and string.' => 'Разрешённые типы: integer, float и string.',
'{Property} must be no less than {min}.' => '{Property} должно быть не меньше {min}.',
'{Property} must be no greater than {max}.' => '{Property} должно быть не больше {max}.',

Expand All @@ -157,22 +160,41 @@
* @see \Yiisoft\Validator\Rule\Date\Date
* @see \Yiisoft\Validator\Rule\Date\DateTime
*/
'Invalid date value.' => 'Некорректное значение даты.',
'{Property} must be a date' => '{Property} должно быть датой.',

/**
* @see \Yiisoft\Validator\Rule\Date\Time
*/
'Invalid time value.' => 'Некорректное значение времени.',
'{Property} must be a time.' => '{Property} должно быть временем.',

/** @see UniqueIterable */
'The allowed types for iterable\'s item values are integer, float, string, boolean, null and object implementing \Stringable or \DateTimeInterface.' => 'Разрешённые типы для значений элементов списка: integer, float, string, boolean, null и объект, реализующий интерфейс \Stringable или \DateTimeInterface.',
'All iterable items must have the same type.' => 'Все элементы списка должны иметь одинаковый тип.',
'Every iterable\'s item must be unique.' => 'Каждый элемент списка должен быть уникален.',
'The allowed types for iterable\'s item values of {property} are integer, float, string, boolean, null and object implementing \Stringable or \DateTimeInterface.' =>
'Разрешённые типы для значений элементов списка {property}: integer, float, string, boolean, null и объект, реализующий интерфейс \Stringable или \DateTimeInterface.',
'All iterable items of {property} must have the same type.' =>
'Все элементы списка {property} должны иметь одинаковый тип.',
'Every iterable\'s item must be unique.' => 'Каждый элемент списка {property} должен быть уникален.',

/** @see BooleanType */
'Value must be a boolean.' => 'Значение должно быть булевым.',
'{Property} must be a boolean.' => 'Значение должно быть булевым.',
/** @see FloatType */
'Value must be a float.' => 'Значение должно быть вещественным числом.',
'{Property} must be a float.' => 'Значение должно быть вещественным числом.',
/** @see AnyRule */
'At least one of the inner rules must pass the validation.' => 'Как минимум одно из внутренних правил должно пройти валидацию',

/** @see Image */
'{Property} must be an image.' => '{Property} должно быть изображением.',
'The width of {property} must be exactly {exactly, number} {exactly, plural, one{pixel} other{pixels}}.' =>
'Ширина {propery} должна быть в точности {exactly, number} {exactly, plural, one{пиксель} other{пикселей}}',
'The height of {property} must be exactly {exactly, number} {exactly, plural, one{pixel} other{pixels}}.' =>
'Высота {propery} должна быть в точности {exactly, number} {exactly, plural, one{пиксель} other{пикселей}}',
'The width of {property} cannot be smaller than {limit, number} {limit, plural, one{pixel} other{pixels}}.' =>
'Ширина {property} не может быть меньше {limit, number} {limit, plural, one{пикселя} other{пикселей}}.',
'The height of {property} cannot be smaller than {limit, number} {limit, plural, one{pixel} other{pixels}}.' =>
'Высота {property} не может быть меньше {limit, number} {limit, plural, one{пикселя} other{пикселей}}.',
'The width of {property} cannot be larger than {limit, number} {limit, plural, one{pixel} other{pixels}}.' =>
'Ширина {property} не может быть больше {limit, number} {limit, plural, one{пикселя} other{пикселей}}.',
'The height of {property}t cannot be larger than {limit, number} {limit, plural, one{pixel} other{pixels}}.' =>
'Высота {property} не может быть больше {limit, number} {limit, plural, one{пикселя} other{пикселей}}.',
'The aspect ratio of {property} must be {aspectRatioWidth, number}:{aspectRatioHeight, number} with margin {aspectRatioMargin, number}%.' =>
'Соотношение стороно {property} должно быть {aspectRatioWidth, number}:{aspectRatioHeight, number} с отступом {aspectRatioMargin, number}%.',
];
10 changes: 5 additions & 5 deletions src/Rule/AbstractCompare.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ abstract class AbstractCompare implements
/**
* A default for {@see $incorrectInputMessage}.
*/
protected const DEFAULT_INCORRECT_INPUT_MESSAGE = 'The allowed types are integer, float, string, boolean, null ' .
'and object implementing \Stringable interface or \DateTimeInterface.';
protected const DEFAULT_INCORRECT_INPUT_MESSAGE = 'The allowed types for {property} are integer, float, string, ' .
'boolean, null and object implementing \Stringable interface or \DateTimeInterface.';
/**
* A default for {@see $incorrectDataSetTypeMessage}.
*/
protected const DEFAULT_INCORRECT_DATA_SET_TYPE_MESSAGE = 'The property value returned from a custom data set ' .
'must have one of the following types: integer, float, string, boolean, null or an object implementing ' .
'\Stringable interface or \DateTimeInterface.';
protected const DEFAULT_INCORRECT_DATA_SET_TYPE_MESSAGE = '{Property} returned from a custom data set must have ' .
'one of the following types: integer, float, string, boolean, null or an object implementing \Stringable ' .
'interface or \DateTimeInterface.';
/**
* List of valid types.
*
Expand Down
2 changes: 1 addition & 1 deletion src/Rule/AbstractNumber.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ abstract class AbstractNumber implements
/**
* A default for {@see $incorrectInputMessage}.
*/
protected const DEFAULT_INCORRECT_INPUT_MESSAGE = 'The allowed types are integer, float and string.';
protected const DEFAULT_INCORRECT_INPUT_MESSAGE = 'The allowed types for {property} are integer, float and string.';
/**
* A default for {@see $lessThanMinMessage}.
*/
Expand Down
4 changes: 3 additions & 1 deletion src/Rule/AtLeast.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ final class AtLeast implements DumpedRuleInterface, SkipOnErrorInterface, WhenIn
* You may use the following placeholders in the message:
*
* - `{property}`: the translated label of the property being validated.
* - `{properties} - the translated labels of the properties some of which must be filled (within the property being
* validated).
* - `{min}`: the minimum number of property values that was not met.
* @param bool|callable|null $skipOnEmpty Whether to skip this rule if the value validated is empty.
* See {@see SkipOnEmptyInterface}.
Expand All @@ -64,7 +66,7 @@ public function __construct(
private int $min = 1,
private string $incorrectInputMessage = '{Property} must be an array or an object.',
private string $message = 'At least {min, number} {min, plural, one{property} other{properties}} from this ' .
'list must be filled: {properties}.',
'list must be filled for {property}: {properties}.',
bool|callable|null $skipOnEmpty = null,
private bool $skipOnError = false,
private Closure|null $when = null
Expand Down
2 changes: 2 additions & 0 deletions src/Rule/AtLeastHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ public function validate(mixed $value, RuleInterface $rule, ValidationContext $c

if ($filledCount < $rule->getMin()) {
$result->addError($rule->getMessage(), [
'property' => $context->getTranslatedProperty(),
'Property' => $context->getCapitalizedTranslatedProperty(),
'properties' => $this->getFormattedPropertiesString($rule->getProperties(), $context),
'Properties' => $this->getCapitalizedPropertiesString($rule->getProperties(), $context),
'min' => $rule->getMin(),
Expand Down
3 changes: 2 additions & 1 deletion src/Rule/BooleanValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ public function __construct(
private int|float|string|bool $trueValue = '1',
private int|float|string|bool $falseValue = '0',
private bool $strict = false,
private string $incorrectInputMessage = 'The allowed types are integer, float, string, boolean. {type} given.',
private string $incorrectInputMessage = 'The allowed types for {property} are integer, float, string, ' .
'boolean. {type} given.',
private string $message = '{Property} must be either "{true}" or "{false}".',
bool|callable|null $skipOnEmpty = null,
private bool $skipOnError = false,
Expand Down
2 changes: 2 additions & 0 deletions src/Rule/CompareHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ public function validate(mixed $value, RuleInterface $rule, ValidationContext $c
$targetValue = $context->getDataSet()->getPropertyValue($targetProperty);
if (!$this->isInputCorrect($rule->getType(), $targetValue)) {
return $result->addError($rule->getIncorrectDataSetTypeMessage(), [
'property' => $context->getTranslatedProperty(),
'Property' => $context->getCapitalizedTranslatedProperty(),
'type' => get_debug_type($targetValue),
]);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Rule/Date/DateHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function __construct(
?string $locale = null,
?string $messageFormat = null,
?int $messageDateType = IntlDateFormatter::SHORT,
string $incorrectInputMessage = 'Invalid date value.',
string $incorrectInputMessage = '{Property} must be a date.',
string $tooEarlyMessage = '{Property} must be no early than {limit}.',
string $tooLateMessage = '{Property} must be no late than {limit}.',
) {
Expand Down
2 changes: 1 addition & 1 deletion src/Rule/Date/DateTimeHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function __construct(
?string $messageFormat = null,
?int $messageDateType = IntlDateFormatter::SHORT,
?int $messageTimeType = IntlDateFormatter::SHORT,
string $incorrectInputMessage = 'Invalid date value.',
string $incorrectInputMessage = '{Property} must be a date.',
string $tooEarlyMessage = '{Property} must be no early than {limit}.',
string $tooLateMessage = '{Property} must be no late than {limit}.',
) {
Expand Down
2 changes: 1 addition & 1 deletion src/Rule/Date/TimeHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function __construct(
?string $locale = null,
?string $messageFormat = null,
?int $messageTimeType = IntlDateFormatter::SHORT,
string $incorrectInputMessage = 'Invalid time value.',
string $incorrectInputMessage = '{Property} must be a time.',
string $tooEarlyMessage = '{Property} must be no early than {limit}.',
string $tooLateMessage = '{Property} must be no late than {limit}.',
) {
Expand Down
3 changes: 2 additions & 1 deletion src/Rule/Each.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ final class Each implements
public function __construct(
callable|iterable|object|string $rules = [],
private string $incorrectInputMessage = '{Property} must be array or iterable.',
private string $incorrectInputKeyMessage = 'Every iterable key must have an integer or a string type.',
private string $incorrectInputKeyMessage = 'Every iterable key of {property} must have an integer or a ' .
'string type.',
bool|callable|null $skipOnEmpty = null,
private bool $skipOnError = false,
private Closure|null $when = null,
Expand Down
Loading

0 comments on commit 23a9b0c

Please sign in to comment.