diff --git a/lib/Cake/Model/Model.php b/lib/Cake/Model/Model.php index f5b8ec92135..dd89cf13695 100644 --- a/lib/Cake/Model/Model.php +++ b/lib/Cake/Model/Model.php @@ -3189,6 +3189,11 @@ public function invalidFields($options = array()) { if (is_array($validator['rule']) && $args === null) { $args = array_slice($ruleSet[$index]['rule'], 1); } + if (!empty($args)) { + foreach ($args as $k => $arg) { + $args[$k] = __d($validationDomain, $arg); + } + } $message = __d($validationDomain, $message, $args); } elseif (is_string($index)) { if (is_array($validator['rule'])) { diff --git a/lib/Cake/Test/Case/Model/ModelValidationTest.php b/lib/Cake/Test/Case/Model/ModelValidationTest.php index b2b79c66ca1..8c0be4162cb 100644 --- a/lib/Cake/Test/Case/Model/ModelValidationTest.php +++ b/lib/Cake/Test/Case/Model/ModelValidationTest.php @@ -761,6 +761,44 @@ public function testValidationMessageAsArray() { $this->assertEquals($expected, $TestModel->validationErrors); } +/** + * Test validation message translation + * + * @return void + */ + public function testValidationMessageTranslation() { + $lang = Configure::read('Config.language'); + Configure::write('Config.language', 'en'); + App::build(array( + 'Locale' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Locale' . DS), + ), App::RESET); + + $TestModel = new ValidationTest1(); + $TestModel->validationDomain = 'validation_messages'; + $TestModel->validate = array( + 'title' => array( + array( + 'rule' => array('customValidationMethod', 'arg1'), + 'required' => true, + 'message' => 'Validation failed: %s' + ) + ) + ); + + $TestModel->create(); + $TestModel->invalidFields(); + $expected = array( + 'title' => array( + 'Translated validation failed: Translated arg1', + ) + ); + $this->assertEquals($expected, $TestModel->validationErrors); + + $TestModel->validationDomain = 'default'; + Configure::write('Config.language', $lang); + App::build(); + } + /** * Test for 'on' => [create|update] in validation rules. * diff --git a/lib/Cake/Test/test_app/Locale/eng/LC_MESSAGES/validation_messages.po b/lib/Cake/Test/test_app/Locale/eng/LC_MESSAGES/validation_messages.po new file mode 100644 index 00000000000..4559a2a6874 --- /dev/null +++ b/lib/Cake/Test/test_app/Locale/eng/LC_MESSAGES/validation_messages.po @@ -0,0 +1,5 @@ +msgid "Validation failed: %s" +msgstr "Translated validation failed: %s" + +msgid "arg1" +msgstr "Translated arg1" \ No newline at end of file