Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lumen (laravel) translation in controller

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!

like image 288
Peter Avatar asked Dec 05 '22 17:12

Peter


2 Answers

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

like image 85
KuKeC Avatar answered Dec 09 '22 14:12

KuKeC


trans it's a global function, so you can use it directly from your controller or Closure

Route::get('/', function () {

    echo trans('messages.welcome');

});
like image 22
huuuk Avatar answered Dec 09 '22 14:12

huuuk