I need to translate strings which are used in (email-)jobs and controllers.
I read this: https://laravel.com/docs/5.2/localization so I know you can get in in the view with:
echo trans("messages.welcome");
But it's an Lumen api and I do not use the view.
How can i get the translator in a controller or a job.
Thanks in advance!
To get the translator in controller you need to use it like below
//include in your controller
use Lang;
//in code you get values like
Lang::get('messages.error');
Hope it helps
trans
it's a global function, so you can use it directly from your controller or Closure
Route::get('/', function () {
echo trans('messages.welcome');
});
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