Home > Back-end >  i18n translations not working in Controller
i18n translations not working in Controller

Time:02-05

Why would i18n translations work in a view, but not in AppController?

Doesn't work - In AppController:

class AppController extends Controller
{
    public function initialize()
    {
        parent::initialize();
        
        debug(__('My English Text'));
        ...
    }
}

Works - In my view:

<p><?= __('My English Text') ?></p>

CodePudding user response:

I simply had to set the language before calling __(). In my case, it was being set further down the chain.

CodePudding user response:

You can use it like this


$test = __('My English Text');
dd($test);

  •  Tags:  
  • Related