Commit 4239b2a5 by Alexander Makarov

Fixes #1870: Validation errors weren't properly translated when using clientside validation

parent 718ddfb9
...@@ -24,6 +24,7 @@ Yii Framework 2 Change Log ...@@ -24,6 +24,7 @@ Yii Framework 2 Change Log
- Bug #1798: Fixed label attributes for array fields (zhuravljov) - Bug #1798: Fixed label attributes for array fields (zhuravljov)
- Bug #1800: Better check for `$_SERVER['HTTPS']` in `yii\web\Request::getIsSecureConnection()` (ginus, samdark) - Bug #1800: Better check for `$_SERVER['HTTPS']` in `yii\web\Request::getIsSecureConnection()` (ginus, samdark)
- Bug #1827: Debugger toolbar is loaded twice if an action is calling `run()` to execute another action (qiangxue) - Bug #1827: Debugger toolbar is loaded twice if an action is calling `run()` to execute another action (qiangxue)
- Bug #1870: Validation errors weren't properly translated when using clientside validation (samdark)
- Bug: Fixed `Call to a member function registerAssetFiles() on a non-object` in case of wrong `sourcePath` for an asset bundle (samdark) - Bug: Fixed `Call to a member function registerAssetFiles() on a non-object` in case of wrong `sourcePath` for an asset bundle (samdark)
- Bug: Fixed incorrect event name for `yii\jui\Spinner` (samdark) - Bug: Fixed incorrect event name for `yii\jui\Spinner` (samdark)
- Bug: Json::encode() did not handle objects that implement JsonSerializable interface correctly (cebe) - Bug: Json::encode() did not handle objects that implement JsonSerializable interface correctly (cebe)
......
...@@ -72,10 +72,10 @@ class BooleanValidator extends Validator ...@@ -72,10 +72,10 @@ class BooleanValidator extends Validator
$options = [ $options = [
'trueValue' => $this->trueValue, 'trueValue' => $this->trueValue,
'falseValue' => $this->falseValue, 'falseValue' => $this->falseValue,
'message' => strtr($this->message, [ 'message' => Yii::t('yii', $this->message, [
'{attribute}' => $object->getAttributeLabel($attribute), 'attribute' => $object->getAttributeLabel($attribute),
'{true}' => $this->trueValue, 'true' => $this->trueValue,
'{false}' => $this->falseValue, 'false' => $this->falseValue,
]), ]),
]; ];
if ($this->skipOnEmpty) { if ($this->skipOnEmpty) {
......
...@@ -195,10 +195,10 @@ class CompareValidator extends Validator ...@@ -195,10 +195,10 @@ class CompareValidator extends Validator
$options['skipOnEmpty'] = 1; $options['skipOnEmpty'] = 1;
} }
$options['message'] = strtr($this->message, [ $options['message'] = Yii::t('yii', $this->message, [
'{attribute}' => $object->getAttributeLabel($attribute), 'attribute' => $object->getAttributeLabel($attribute),
'{compareAttribute}' => $compareValue, 'compareAttribute' => $compareValue,
'{compareValue}' => $compareValue, 'compareValue' => $compareValue,
]); ]);
ValidationAsset::register($view); ValidationAsset::register($view);
......
...@@ -98,8 +98,8 @@ class EmailValidator extends Validator ...@@ -98,8 +98,8 @@ class EmailValidator extends Validator
'pattern' => new JsExpression($this->pattern), 'pattern' => new JsExpression($this->pattern),
'fullPattern' => new JsExpression($this->fullPattern), 'fullPattern' => new JsExpression($this->fullPattern),
'allowName' => $this->allowName, 'allowName' => $this->allowName,
'message' => strtr($this->message, [ 'message' => Yii::t('yii', $this->message, [
'{attribute}' => $object->getAttributeLabel($attribute), 'attribute' => $object->getAttributeLabel($attribute),
]), ]),
'enableIDN' => (boolean)$this->enableIDN, 'enableIDN' => (boolean)$this->enableIDN,
]; ];
......
...@@ -124,23 +124,23 @@ class NumberValidator extends Validator ...@@ -124,23 +124,23 @@ class NumberValidator extends Validator
$options = [ $options = [
'pattern' => new JsExpression($this->integerOnly ? $this->integerPattern : $this->numberPattern), 'pattern' => new JsExpression($this->integerOnly ? $this->integerPattern : $this->numberPattern),
'message' => strtr($this->message, [ 'message' => Yii::t('yii', $this->message, [
'{attribute}' => $label, 'attribute' => $label,
]), ]),
]; ];
if ($this->min !== null) { if ($this->min !== null) {
$options['min'] = $this->min; $options['min'] = $this->min;
$options['tooSmall'] = strtr($this->tooSmall, [ $options['tooSmall'] = Yii::t('yii', $this->tooSmall, [
'{attribute}' => $label, 'attribute' => $label,
'{min}' => $this->min, 'min' => $this->min,
]); ]);
} }
if ($this->max !== null) { if ($this->max !== null) {
$options['max'] = $this->max; $options['max'] = $this->max;
$options['tooBig'] = strtr($this->tooBig, [ $options['tooBig'] = Yii::t('yii', $this->tooBig, [
'{attribute}' => $label, 'attribute' => $label,
'{max}' => $this->max, 'max' => $this->max,
]); ]);
} }
if ($this->skipOnEmpty) { if ($this->skipOnEmpty) {
......
...@@ -73,8 +73,8 @@ class RangeValidator extends Validator ...@@ -73,8 +73,8 @@ class RangeValidator extends Validator
$options = [ $options = [
'range' => $range, 'range' => $range,
'not' => $this->not, 'not' => $this->not,
'message' => strtr($this->message, [ 'message' => Yii::t('yii', $this->message, [
'{attribute}' => $object->getAttributeLabel($attribute), 'attribute' => $object->getAttributeLabel($attribute),
]), ]),
]; ];
if ($this->skipOnEmpty) { if ($this->skipOnEmpty) {
......
...@@ -80,8 +80,8 @@ class RegularExpressionValidator extends Validator ...@@ -80,8 +80,8 @@ class RegularExpressionValidator extends Validator
$options = [ $options = [
'pattern' => new JsExpression($pattern), 'pattern' => new JsExpression($pattern),
'not' => $this->not, 'not' => $this->not,
'message' => strtr($this->message, [ 'message' => Yii::t('yii', $this->message, [
'{attribute}' => $object->getAttributeLabel($attribute), 'attribute' => $object->getAttributeLabel($attribute),
]), ]),
]; ];
if ($this->skipOnEmpty) { if ($this->skipOnEmpty) {
......
...@@ -90,8 +90,8 @@ class RequiredValidator extends Validator ...@@ -90,8 +90,8 @@ class RequiredValidator extends Validator
{ {
$options = []; $options = [];
if ($this->requiredValue !== null) { if ($this->requiredValue !== null) {
$options['message'] = strtr($this->message, [ $options['message'] = Yii::t('yii', $this->message, [
'{requiredValue}' => $this->requiredValue, 'requiredValue' => $this->requiredValue,
]); ]);
$options['requiredValue'] = $this->requiredValue; $options['requiredValue'] = $this->requiredValue;
} else { } else {
...@@ -101,8 +101,8 @@ class RequiredValidator extends Validator ...@@ -101,8 +101,8 @@ class RequiredValidator extends Validator
$options['strict'] = 1; $options['strict'] = 1;
} }
$options['message'] = strtr($options['message'], [ $options['message'] = Yii::t('yii', $options['message'], [
'{attribute}' => $object->getAttributeLabel($attribute), 'attribute' => $object->getAttributeLabel($attribute),
]); ]);
ValidationAsset::register($view); ValidationAsset::register($view);
......
...@@ -151,30 +151,30 @@ class StringValidator extends Validator ...@@ -151,30 +151,30 @@ class StringValidator extends Validator
$label = $object->getAttributeLabel($attribute); $label = $object->getAttributeLabel($attribute);
$options = [ $options = [
'message' => strtr($this->message, [ 'message' => Yii::t('yii', $this->message, [
'{attribute}' => $label, '{attribute}' => $label,
]), ]),
]; ];
if ($this->min !== null) { if ($this->min !== null) {
$options['min'] = $this->min; $options['min'] = $this->min;
$options['tooShort'] = strtr($this->tooShort, [ $options['tooShort'] = Yii::t('yii', $this->tooShort, [
'{attribute}' => $label, 'attribute' => $label,
'{min}' => $this->min, 'min' => $this->min,
]); ]);
} }
if ($this->max !== null) { if ($this->max !== null) {
$options['max'] = $this->max; $options['max'] = $this->max;
$options['tooLong'] = strtr($this->tooLong, [ $options['tooLong'] = Yii::t('yii', $this->tooLong, [
'{attribute}' => $label, 'attribute' => $label,
'{max}' => $this->max, 'max' => $this->max,
]); ]);
} }
if ($this->length !== null) { if ($this->length !== null) {
$options['is'] = $this->length; $options['is'] = $this->length;
$options['notEqual'] = strtr($this->notEqual, [ $options['notEqual'] = Yii::t('yii', $this->notEqual, [
'{attribute}' => $label, 'attribute' => $label,
'{length}' => $this->length, 'length' => $this->length,
]); ]);
} }
if ($this->skipOnEmpty) { if ($this->skipOnEmpty) {
......
...@@ -121,8 +121,8 @@ class UrlValidator extends Validator ...@@ -121,8 +121,8 @@ class UrlValidator extends Validator
$options = [ $options = [
'pattern' => new JsExpression($pattern), 'pattern' => new JsExpression($pattern),
'message' => strtr($this->message, [ 'message' => Yii::t('yii', $this->message, [
'{attribute}' => $object->getAttributeLabel($attribute), 'attribute' => $object->getAttributeLabel($attribute),
]), ]),
'enableIDN' => (boolean)$this->enableIDN, 'enableIDN' => (boolean)$this->enableIDN,
]; ];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment