@@ -68,6 +68,13 @@ class Validator implements MessageProviderInterface {
6868 */
6969 protected $ customMessages = array ();
7070
71+ /**
72+ * The array of fallback error messages.
73+ *
74+ * @var array
75+ */
76+ protected $ fallbackMessages = array ();
77+
7178 /**
7279 * The array of custom attribute names.
7380 *
@@ -1094,34 +1101,38 @@ protected function getMessage($attribute, $rule)
10941101 // Finally, if no developer specified messages have been set, and no other
10951102 // special messages apply for this rule, we will just pull the default
10961103 // messages out of the translator service for this validation rule.
1097- else
1098- {
1099- $ key = "validation. {$ lowerRule }" ;
1104+ $ key = "validation. {$ lowerRule }" ;
11001105
1101- return $ this ->translator ->trans ($ key );
1106+ if ($ key != ($ value = $ this ->translator ->trans ($ key )))
1107+ {
1108+ return $ value ;
11021109 }
1110+
1111+ return $ this ->getInlineMessage (
1112+ $ attribute , $ lowerRule , $ this ->fallbackMessages
1113+ ) ?: $ key ;
11031114 }
11041115
11051116 /**
11061117 * Get the inline message for a rule if it exists.
11071118 *
11081119 * @param string $attribute
11091120 * @param string $lowerRule
1121+ * @param array $source
11101122 * @return string
11111123 */
1112- protected function getInlineMessage ($ attribute , $ lowerRule )
1124+ protected function getInlineMessage ($ attribute , $ lowerRule, $ source = null )
11131125 {
1126+ $ source = $ source ?: $ this ->customMessages ;
1127+
11141128 $ keys = array ("{$ attribute }. {$ lowerRule }" , $ lowerRule );
11151129
11161130 // First we will check for a custom message for an attribute specific rule
11171131 // message for the fields, then we will check for a general custom line
11181132 // that is not attribute specific. If we find either we'll return it.
11191133 foreach ($ keys as $ key )
11201134 {
1121- if (isset ($ this ->customMessages [$ key ]))
1122- {
1123- return $ this ->customMessages [$ key ];
1124- }
1135+ if (isset ($ source [$ key ])) return $ source [$ key ];
11251136 }
11261137 }
11271138
@@ -1764,6 +1775,27 @@ public function setCustomMessages(array $messages)
17641775 $ this ->customMessages = array_merge ($ this ->customMessages , $ messages );
17651776 }
17661777
1778+ /**
1779+ * Get the fallback messages for the validator.
1780+ *
1781+ * @return void
1782+ */
1783+ public function getFallbackMessages ()
1784+ {
1785+ return $ this ->fallbackMessages ;
1786+ }
1787+
1788+ /**
1789+ * Set the fallback messages for the validator.
1790+ *
1791+ * @param array $messages
1792+ * @return void
1793+ */
1794+ public function setFallbackMessages (array $ messages )
1795+ {
1796+ $ this ->fallbackMessages = $ messages ;
1797+ }
1798+
17671799 /**
17681800 * Get the failed validation rules.
17691801 *
0 commit comments