diff --git a/lib/Cake/Console/Command/Task/ExtractTask.php b/lib/Cake/Console/Command/Task/ExtractTask.php index b652e9e54..61de93e9e 100644 --- a/lib/Cake/Console/Command/Task/ExtractTask.php +++ b/lib/Cake/Console/Command/Task/ExtractTask.php @@ -390,7 +390,12 @@ class ExtractTask extends Shell { foreach ($rules as $rule => $validateProp) { if (isset($validateProp['message'])) { - $this->_strings[$domain][$validateProp['message']][$file][] = 'validation for field ' . $field; + if (is_array($validateProp['message'])) { + $message = $validateProp['message'][0]; + } else { + $message = $validateProp['message']; + } + $this->_strings[$domain][$message][$file][] = 'validation for field ' . $field; } } } @@ -504,7 +509,7 @@ class ExtractTask extends Shell { $output .= "\"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\\n\"\n\n"; return $output; } - + /** * Get the strings from the position forward * diff --git a/lib/Cake/Model/Model.php b/lib/Cake/Model/Model.php index e980fb4cd..f8bd33103 100644 --- a/lib/Cake/Model/Model.php +++ b/lib/Cake/Model/Model.php @@ -2271,7 +2271,7 @@ class Model extends Object { return null; } } - + return $query; } @@ -2754,6 +2754,13 @@ class Model extends Object { } else { $validator['message'] = __d($validationDomain, $message); } + } elseif (is_array($validator['message'])) { + if (count($validator['message']) > 1) { + $args = array_slice($validator['message'], 1); + } else { + $args = $validator['rule']; + } + $validator['message'] = __d($validationDomain, $validator['message'][0], $args); } $this->invalidate($fieldName, $validator['message']); diff --git a/lib/Cake/Test/Case/Console/Command/Task/ExtractTaskTest.php b/lib/Cake/Test/Case/Console/Command/Task/ExtractTaskTest.php index 4032d5109..a0ee63330 100644 --- a/lib/Cake/Test/Case/Console/Command/Task/ExtractTaskTest.php +++ b/lib/Cake/Test/Case/Console/Command/Task/ExtractTaskTest.php @@ -293,6 +293,9 @@ class ExtractTaskTest extends CakeTestCase { $pattern = '#msgid "Post title is required"#'; $this->assertPattern($pattern, $result); + $pattern = '#msgid "You may enter up to %s chars \(minimum is %s chars\)"#'; + $this->assertPattern($pattern, $result); + $pattern = '#msgid "Post body is required"#'; $this->assertPattern($pattern, $result); diff --git a/lib/Cake/Test/Case/Model/ModelValidationTest.php b/lib/Cake/Test/Case/Model/ModelValidationTest.php index bf9282955..14201ae53 100644 --- a/lib/Cake/Test/Case/Model/ModelValidationTest.php +++ b/lib/Cake/Test/Case/Model/ModelValidationTest.php @@ -682,4 +682,35 @@ class ModelValidationTest extends BaseModelTest { $this->assertEquals($TestModel->validationErrors, array()); } +/** + * Test placeholder replacement when validation message is an array + * + * @return void + */ + public function testValidationMessageAsArray() { + $TestModel = new ValidationTest1(); + $TestModel->create(array('title' => 'foo')); + $TestModel->validate = array( + 'title' => array( + 'minLength' => array( + 'rule' => array('minLength', 6), + 'message' => array('Minimum length allowed is %d chars'), + 'last' => false + ), + 'between' => array( + 'rule' => array('between', 5, 15), + 'message' => array('You may enter up to %s chars (minimum is %s chars)', 14, 6) + ) + ) + ); + $TestModel->invalidFields(); + $expected = array( + 'title' => array( + 'Minimum length allowed is 6 chars', + 'You may enter up to 14 chars (minimum is 6 chars)' + ) + ); + $this->assertEquals($TestModel->validationErrors, $expected); + } + } diff --git a/lib/Cake/Test/test_app/Model/PersisterOne.php b/lib/Cake/Test/test_app/Model/PersisterOne.php index 716d29edc..5e4b89928 100644 --- a/lib/Cake/Test/test_app/Model/PersisterOne.php +++ b/lib/Cake/Test/test_app/Model/PersisterOne.php @@ -27,10 +27,16 @@ class PersisterOne extends AppModel { public $hasMany = array('Comment', 'TestPlugin.TestPluginComment'); public $validate = array( 'title' => array( - 'rule' => array('custom', '.*'), - 'allowEmpty' => true, - 'required' => false, - 'message' => 'Post title is required' + 'custom' => array( + 'rule' => array('custom', '.*'), + 'allowEmpty' => true, + 'required' => false, + 'message' => 'Post title is required' + ), + 'between' => array( + 'rule' => array('between', 5, 15), + 'message' => array('You may enter up to %s chars (minimum is %s chars)', 14, 6) + ) ), 'body' => array( 'first_rule' => array(