Search code examples
phplaraveltranslationlumen

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!


Solution

  • 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