From 4239b2a5f2fbfc71f2bbf58e6bbe300355403db1 Mon Sep 17 00:00:00 2001
From: Alexander Makarov <sam@rmcreative.ru>
Date: Sun, 12 Jan 2014 21:37:28 +0400
Subject: [PATCH] Fixes #1870: Validation errors weren't properly translated when using clientside validation

---
 framework/CHANGELOG.md                              |  1 +
 framework/validators/BooleanValidator.php           |  8 ++++----
 framework/validators/CompareValidator.php           |  8 ++++----
 framework/validators/EmailValidator.php             |  4 ++--
 framework/validators/NumberValidator.php            | 16 ++++++++--------
 framework/validators/RangeValidator.php             |  4 ++--
 framework/validators/RegularExpressionValidator.php |  4 ++--
 framework/validators/RequiredValidator.php          |  8 ++++----
 framework/validators/StringValidator.php            | 20 ++++++++++----------
 framework/validators/UrlValidator.php               |  4 ++--
 10 files changed, 39 insertions(+), 38 deletions(-)

diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md
index 674e519..7caf9a3 100644
--- a/framework/CHANGELOG.md
+++ b/framework/CHANGELOG.md
@@ -24,6 +24,7 @@ Yii Framework 2 Change Log
 - Bug #1798: Fixed label attributes for array fields (zhuravljov)
 - 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 #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 incorrect event name for `yii\jui\Spinner` (samdark)
 - Bug: Json::encode() did not handle objects that implement JsonSerializable interface correctly (cebe)
diff --git a/framework/validators/BooleanValidator.php b/framework/validators/BooleanValidator.php
index 8bca827..762a537 100644
--- a/framework/validators/BooleanValidator.php
+++ b/framework/validators/BooleanValidator.php
@@ -72,10 +72,10 @@ class BooleanValidator extends Validator
 		$options = [
 			'trueValue' => $this->trueValue,
 			'falseValue' => $this->falseValue,
-			'message' => strtr($this->message, [
-				'{attribute}' => $object->getAttributeLabel($attribute),
-				'{true}' => $this->trueValue,
-				'{false}' => $this->falseValue,
+			'message' => Yii::t('yii', $this->message, [
+				'attribute' => $object->getAttributeLabel($attribute),
+				'true' => $this->trueValue,
+				'false' => $this->falseValue,
 			]),
 		];
 		if ($this->skipOnEmpty) {
diff --git a/framework/validators/CompareValidator.php b/framework/validators/CompareValidator.php
index cbd12d2..be9b646 100644
--- a/framework/validators/CompareValidator.php
+++ b/framework/validators/CompareValidator.php
@@ -195,10 +195,10 @@ class CompareValidator extends Validator
 			$options['skipOnEmpty'] = 1;
 		}
 
-		$options['message'] = strtr($this->message, [
-			'{attribute}' => $object->getAttributeLabel($attribute),
-			'{compareAttribute}' => $compareValue,
-			'{compareValue}' => $compareValue,
+		$options['message'] = Yii::t('yii', $this->message, [
+			'attribute' => $object->getAttributeLabel($attribute),
+			'compareAttribute' => $compareValue,
+			'compareValue' => $compareValue,
 		]);
 
 		ValidationAsset::register($view);
diff --git a/framework/validators/EmailValidator.php b/framework/validators/EmailValidator.php
index e5d9b75..d2a7a23 100644
--- a/framework/validators/EmailValidator.php
+++ b/framework/validators/EmailValidator.php
@@ -98,8 +98,8 @@ class EmailValidator extends Validator
 			'pattern' => new JsExpression($this->pattern),
 			'fullPattern' => new JsExpression($this->fullPattern),
 			'allowName' => $this->allowName,
-			'message' => strtr($this->message, [
-				'{attribute}' => $object->getAttributeLabel($attribute),
+			'message' => Yii::t('yii', $this->message, [
+				'attribute' => $object->getAttributeLabel($attribute),
 			]),
 			'enableIDN' => (boolean)$this->enableIDN,
 		];
diff --git a/framework/validators/NumberValidator.php b/framework/validators/NumberValidator.php
index 1bb2360..4f45b21 100644
--- a/framework/validators/NumberValidator.php
+++ b/framework/validators/NumberValidator.php
@@ -124,23 +124,23 @@ class NumberValidator extends Validator
 
 		$options = [
 			'pattern' => new JsExpression($this->integerOnly ? $this->integerPattern : $this->numberPattern),
-			'message' => strtr($this->message, [
-				'{attribute}' => $label,
+			'message' => Yii::t('yii', $this->message, [
+				'attribute' => $label,
 			]),
 		];
 
 		if ($this->min !== null) {
 			$options['min'] = $this->min;
-			$options['tooSmall'] = strtr($this->tooSmall, [
-				'{attribute}' => $label,
-				'{min}' => $this->min,
+			$options['tooSmall'] = Yii::t('yii', $this->tooSmall, [
+				'attribute' => $label,
+				'min' => $this->min,
 			]);
 		}
 		if ($this->max !== null) {
 			$options['max'] = $this->max;
-			$options['tooBig'] = strtr($this->tooBig, [
-				'{attribute}' => $label,
-				'{max}' => $this->max,
+			$options['tooBig'] = Yii::t('yii', $this->tooBig, [
+				'attribute' => $label,
+				'max' => $this->max,
 			]);
 		}
 		if ($this->skipOnEmpty) {
diff --git a/framework/validators/RangeValidator.php b/framework/validators/RangeValidator.php
index a4da139..c8694da 100644
--- a/framework/validators/RangeValidator.php
+++ b/framework/validators/RangeValidator.php
@@ -73,8 +73,8 @@ class RangeValidator extends Validator
 		$options = [
 			'range' => $range,
 			'not' => $this->not,
-			'message' => strtr($this->message, [
-				'{attribute}' => $object->getAttributeLabel($attribute),
+			'message' => Yii::t('yii', $this->message, [
+				'attribute' => $object->getAttributeLabel($attribute),
 			]),
 		];
 		if ($this->skipOnEmpty) {
diff --git a/framework/validators/RegularExpressionValidator.php b/framework/validators/RegularExpressionValidator.php
index 28e9bdc..6e5011b 100644
--- a/framework/validators/RegularExpressionValidator.php
+++ b/framework/validators/RegularExpressionValidator.php
@@ -80,8 +80,8 @@ class RegularExpressionValidator extends Validator
 		$options = [
 			'pattern' => new JsExpression($pattern),
 			'not' => $this->not,
-			'message' => strtr($this->message, [
-				'{attribute}' => $object->getAttributeLabel($attribute),
+			'message' => Yii::t('yii', $this->message, [
+				'attribute' => $object->getAttributeLabel($attribute),
 			]),
 		];
 		if ($this->skipOnEmpty) {
diff --git a/framework/validators/RequiredValidator.php b/framework/validators/RequiredValidator.php
index f291f39..c0e1ed9 100644
--- a/framework/validators/RequiredValidator.php
+++ b/framework/validators/RequiredValidator.php
@@ -90,8 +90,8 @@ class RequiredValidator extends Validator
 	{
 		$options = [];
 		if ($this->requiredValue !== null) {
-			$options['message'] = strtr($this->message, [
-				'{requiredValue}' => $this->requiredValue,
+			$options['message'] = Yii::t('yii', $this->message, [
+				'requiredValue' => $this->requiredValue,
 			]);
 			$options['requiredValue'] = $this->requiredValue;
 		} else {
@@ -101,8 +101,8 @@ class RequiredValidator extends Validator
 			$options['strict'] = 1;
 		}
 
-		$options['message'] = strtr($options['message'], [
-			'{attribute}' => $object->getAttributeLabel($attribute),
+		$options['message'] = Yii::t('yii', $options['message'], [
+			'attribute' => $object->getAttributeLabel($attribute),
 		]);
 
 		ValidationAsset::register($view);
diff --git a/framework/validators/StringValidator.php b/framework/validators/StringValidator.php
index 7d15aa7..e28ae1d 100644
--- a/framework/validators/StringValidator.php
+++ b/framework/validators/StringValidator.php
@@ -151,30 +151,30 @@ class StringValidator extends Validator
 		$label = $object->getAttributeLabel($attribute);
 
 		$options = [
-			'message' => strtr($this->message, [
+			'message' => Yii::t('yii', $this->message, [
 				'{attribute}' => $label,
 			]),
 		];
 
 		if ($this->min !== null) {
 			$options['min'] = $this->min;
-			$options['tooShort'] = strtr($this->tooShort, [
-				'{attribute}' => $label,
-				'{min}' => $this->min,
+			$options['tooShort'] = Yii::t('yii', $this->tooShort, [
+				'attribute' => $label,
+				'min' => $this->min,
 			]);
 		}
 		if ($this->max !== null) {
 			$options['max'] = $this->max;
-			$options['tooLong'] = strtr($this->tooLong, [
-				'{attribute}' => $label,
-				'{max}' => $this->max,
+			$options['tooLong'] = Yii::t('yii', $this->tooLong, [
+				'attribute' => $label,
+				'max' => $this->max,
 			]);
 		}
 		if ($this->length !== null) {
 			$options['is'] = $this->length;
-			$options['notEqual'] = strtr($this->notEqual, [
-				'{attribute}' => $label,
-				'{length}' => $this->length,
+			$options['notEqual'] = Yii::t('yii', $this->notEqual, [
+				'attribute' => $label,
+				'length' => $this->length,
 			]);
 		}
 		if ($this->skipOnEmpty) {
diff --git a/framework/validators/UrlValidator.php b/framework/validators/UrlValidator.php
index 4cb20f6..a60640a 100644
--- a/framework/validators/UrlValidator.php
+++ b/framework/validators/UrlValidator.php
@@ -121,8 +121,8 @@ class UrlValidator extends Validator
 
 		$options = [
 			'pattern' => new JsExpression($pattern),
-			'message' => strtr($this->message, [
-				'{attribute}' => $object->getAttributeLabel($attribute),
+			'message' => Yii::t('yii', $this->message, [
+				'attribute' => $object->getAttributeLabel($attribute),
 			]),
 			'enableIDN' => (boolean)$this->enableIDN,
 		];
--
libgit2 0.27.1