Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel get translated validation errors

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'
        ];
    }
}
like image 631
George Khachidze Avatar asked Jan 20 '16 19:01

George Khachidze


2 Answers

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'
]
like image 107
Fester Avatar answered Oct 21 '22 01:10

Fester


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 :)

like image 45
BKF Avatar answered Oct 21 '22 00:10

BKF