I use Laravel 5.1, I want to return translated validation error in this request class. Please any help how to return translated data.
class ContactRequest extends Request
{
public function authorize()
{
return true;
}
public function rules()
{
return [
'name' => 'required',
'g-recaptcha-response' => 'required|captcha',
'email' => 'required|email',
'message' => 'required',
'phone' => 'required'
];
}
}
In the resources/lang/en
folder, there is a file named validation.php
. Put the translated error messages in the file as described in the laravel documentation.
How your ru/validation.php
file should look (but with russian text):
return [
'required' => ':attribute is required',
'email' => 'You need to enter a valid :attribute',
'captcha' => 'This :attribute is invalid'
]
First install this package : laravel langs (Copy languages folders you wish integrate into resources/lang)
Change locale variable in config/app to 'ru' for example, and that's all :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With