mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-03 22:32:40 +08:00
fixes #1870: better fix that is message extractor friendly
This commit is contained in:
@ -72,11 +72,11 @@ class BooleanValidator extends Validator
|
||||
$options = [
|
||||
'trueValue' => $this->trueValue,
|
||||
'falseValue' => $this->falseValue,
|
||||
'message' => Yii::t('yii', $this->message, [
|
||||
'message' => Yii::$app->getI18n()->format($this->message, [
|
||||
'attribute' => $object->getAttributeLabel($attribute),
|
||||
'true' => $this->trueValue,
|
||||
'false' => $this->falseValue,
|
||||
]),
|
||||
], Yii::$app->language),
|
||||
];
|
||||
if ($this->skipOnEmpty) {
|
||||
$options['skipOnEmpty'] = 1;
|
||||
|
||||
@ -195,11 +195,11 @@ class CompareValidator extends Validator
|
||||
$options['skipOnEmpty'] = 1;
|
||||
}
|
||||
|
||||
$options['message'] = Yii::t('yii', $this->message, [
|
||||
$options['message'] = Yii::$app->getI18n()->format($this->message, [
|
||||
'attribute' => $object->getAttributeLabel($attribute),
|
||||
'compareAttribute' => $compareValue,
|
||||
'compareValue' => $compareValue,
|
||||
]);
|
||||
], Yii::$app->language);
|
||||
|
||||
ValidationAsset::register($view);
|
||||
return 'yii.validation.compare(value, messages, ' . json_encode($options) . ');';
|
||||
|
||||
@ -98,9 +98,9 @@ class EmailValidator extends Validator
|
||||
'pattern' => new JsExpression($this->pattern),
|
||||
'fullPattern' => new JsExpression($this->fullPattern),
|
||||
'allowName' => $this->allowName,
|
||||
'message' => Yii::t('yii', $this->message, [
|
||||
'message' => Yii::$app->getI18n()->format($this->message, [
|
||||
'attribute' => $object->getAttributeLabel($attribute),
|
||||
]),
|
||||
], Yii::$app->language),
|
||||
'enableIDN' => (boolean)$this->enableIDN,
|
||||
];
|
||||
if ($this->skipOnEmpty) {
|
||||
|
||||
@ -124,24 +124,24 @@ class NumberValidator extends Validator
|
||||
|
||||
$options = [
|
||||
'pattern' => new JsExpression($this->integerOnly ? $this->integerPattern : $this->numberPattern),
|
||||
'message' => Yii::t('yii', $this->message, [
|
||||
'message' => Yii::$app->getI18n()->format($this->message, [
|
||||
'attribute' => $label,
|
||||
]),
|
||||
], Yii::$app->language),
|
||||
];
|
||||
|
||||
if ($this->min !== null) {
|
||||
$options['min'] = $this->min;
|
||||
$options['tooSmall'] = Yii::t('yii', $this->tooSmall, [
|
||||
$options['tooSmall'] = Yii::$app->getI18n()->format($this->tooSmall, [
|
||||
'attribute' => $label,
|
||||
'min' => $this->min,
|
||||
]);
|
||||
], Yii::$app->language);
|
||||
}
|
||||
if ($this->max !== null) {
|
||||
$options['max'] = $this->max;
|
||||
$options['tooBig'] = Yii::t('yii', $this->tooBig, [
|
||||
$options['tooBig'] = Yii::$app->getI18n()->format($this->tooBig, [
|
||||
'attribute' => $label,
|
||||
'max' => $this->max,
|
||||
]);
|
||||
], Yii::$app->language);
|
||||
}
|
||||
if ($this->skipOnEmpty) {
|
||||
$options['skipOnEmpty'] = 1;
|
||||
|
||||
@ -73,9 +73,9 @@ class RangeValidator extends Validator
|
||||
$options = [
|
||||
'range' => $range,
|
||||
'not' => $this->not,
|
||||
'message' => Yii::t('yii', $this->message, [
|
||||
'message' => Yii::$app->getI18n()->format($this->message, [
|
||||
'attribute' => $object->getAttributeLabel($attribute),
|
||||
]),
|
||||
], Yii::$app->language),
|
||||
];
|
||||
if ($this->skipOnEmpty) {
|
||||
$options['skipOnEmpty'] = 1;
|
||||
|
||||
@ -80,9 +80,9 @@ class RegularExpressionValidator extends Validator
|
||||
$options = [
|
||||
'pattern' => new JsExpression($pattern),
|
||||
'not' => $this->not,
|
||||
'message' => Yii::t('yii', $this->message, [
|
||||
'message' => Yii::$app->getI18n()->format($this->message, [
|
||||
'attribute' => $object->getAttributeLabel($attribute),
|
||||
]),
|
||||
], Yii::$app->language),
|
||||
];
|
||||
if ($this->skipOnEmpty) {
|
||||
$options['skipOnEmpty'] = 1;
|
||||
|
||||
@ -90,9 +90,9 @@ class RequiredValidator extends Validator
|
||||
{
|
||||
$options = [];
|
||||
if ($this->requiredValue !== null) {
|
||||
$options['message'] = Yii::t('yii', $this->message, [
|
||||
$options['message'] = Yii::$app->getI18n()->format($this->message, [
|
||||
'requiredValue' => $this->requiredValue,
|
||||
]);
|
||||
], Yii::$app->language);
|
||||
$options['requiredValue'] = $this->requiredValue;
|
||||
} else {
|
||||
$options['message'] = $this->message;
|
||||
@ -101,9 +101,9 @@ class RequiredValidator extends Validator
|
||||
$options['strict'] = 1;
|
||||
}
|
||||
|
||||
$options['message'] = Yii::t('yii', $options['message'], [
|
||||
$options['message'] = Yii::$app->getI18n()->format($options['message'], [
|
||||
'attribute' => $object->getAttributeLabel($attribute),
|
||||
]);
|
||||
], Yii::$app->language);
|
||||
|
||||
ValidationAsset::register($view);
|
||||
return 'yii.validation.required(value, messages, ' . json_encode($options) . ');';
|
||||
|
||||
@ -151,31 +151,31 @@ class StringValidator extends Validator
|
||||
$label = $object->getAttributeLabel($attribute);
|
||||
|
||||
$options = [
|
||||
'message' => Yii::t('yii', $this->message, [
|
||||
'message' => Yii::$app->getI18n()->format($this->message, [
|
||||
'{attribute}' => $label,
|
||||
]),
|
||||
], Yii::$app->language),
|
||||
];
|
||||
|
||||
if ($this->min !== null) {
|
||||
$options['min'] = $this->min;
|
||||
$options['tooShort'] = Yii::t('yii', $this->tooShort, [
|
||||
$options['tooShort'] = Yii::$app->getI18n()->format($this->tooShort, [
|
||||
'attribute' => $label,
|
||||
'min' => $this->min,
|
||||
]);
|
||||
], Yii::$app->language);
|
||||
}
|
||||
if ($this->max !== null) {
|
||||
$options['max'] = $this->max;
|
||||
$options['tooLong'] = Yii::t('yii', $this->tooLong, [
|
||||
$options['tooLong'] = Yii::$app->getI18n()->format($this->tooLong, [
|
||||
'attribute' => $label,
|
||||
'max' => $this->max,
|
||||
]);
|
||||
], Yii::$app->language);
|
||||
}
|
||||
if ($this->length !== null) {
|
||||
$options['is'] = $this->length;
|
||||
$options['notEqual'] = Yii::t('yii', $this->notEqual, [
|
||||
$options['notEqual'] = Yii::$app->getI18n()->format($this->notEqual, [
|
||||
'attribute' => $label,
|
||||
'length' => $this->length,
|
||||
]);
|
||||
], Yii::$app->language);
|
||||
}
|
||||
if ($this->skipOnEmpty) {
|
||||
$options['skipOnEmpty'] = 1;
|
||||
|
||||
@ -121,9 +121,9 @@ class UrlValidator extends Validator
|
||||
|
||||
$options = [
|
||||
'pattern' => new JsExpression($pattern),
|
||||
'message' => Yii::t('yii', $this->message, [
|
||||
'message' =>Yii::$app->getI18n()->format($this->message, [
|
||||
'attribute' => $object->getAttributeLabel($attribute),
|
||||
]),
|
||||
], Yii::$app->language),
|
||||
'enableIDN' => (boolean)$this->enableIDN,
|
||||
];
|
||||
if ($this->skipOnEmpty) {
|
||||
|
||||
Reference in New Issue
Block a user