I can tell you why you get the weird behaviour, but I can't help you with the problem you have overall (though I'd be interested to see the eventual solution).
What's happening here is that :attribute is not being inserted into the string till after the inner Lang::get()
call. So here's what happens:
In the validation translation the string it's looking at is: 'The ' . Lang::get('input.:attribute') . ' is required.'
But at the point it retrieves the string from your validation rules it evaluates the inner Lang::get()
and so you get:
Lang::get('input.:attribute') → 'input.:attribute' (there is no such key `input.:attribute` so return string unchanged)
Leaving the validation string to be translated as:
The input.:attribute is required.
So then this is translated with the validation rule, complete with ':attribute' insertion, which is why you see:
The input.email is required.
Hopefully that makes sense - basically :attribute is not actually evaluated when you think it will be, but later.
'attributes' => array(
'email' => 'E-mail address',
),
'attributes' => array(
'email' => Lang::get('input.email'),
),
Aha that makes sense. I was thinking "surely Laravel has a way to localise field names".
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community