Bin will be removed on June 1, 2014 in favor of http://gist.github.com. Please save all your pastes before then. So long, and thanks for all the fish!×
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
diff --git a/lib/Cake/Console/Command/Task/ExtractTask.php b/lib/Cake/Console/Command/Task/ExtractTask.php
index b652e9e..61de93e 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 e980fb4..f8bd331 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 4032d51..a0ee633 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 bf92829..14201ae 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 716d29e..5e4b899 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(