Whenever I use the
trans() function to return a specific translation from the
validation.php file, it works just perfectly. I have two languages in my application and the translations get returned for both of them.
However, whenever I use the Laravel validator, it returns messages in the default locale only. Is there something I need to specify in the validator? How do I make it work for both languages?
You need to pass as 3rd parameters your translations. Let's assume you have defined your fields, rules and validator like in the following code:
$data = Input::only('title'); $rules['title'] = 'required|min:20|max:80', $validator = Validator::make($data, $rules, Lang::get('forms.validation.entry'));
Now you need to define your translations. Let's assume you need translation for
fr lang so you need co create
lang/fr/forms.php file and put the following content into it:
<?php return array ( 'validation' => array ( 'entry' => array ( 'title.required' => 'Your translation for title required', 'title.min' => 'Your translation for title min', 'title.max' => 'Your translation for title max', ) ) );
Of course you can create file with simpler array but it's just example - instead of
forms.validation.entry it could be for example just
The problem originated from my localization implementation. I've added
App::setLocale(Session::get('lang')); to the
App::before() method in the
filters.php file and it all works now.