October CMS resources and help articles

Simple and to the point. Optimized by the community.

Use message translations in PHP code

2
by mjauvin, last modified on August 12th, 2019

If you need to translate something with Rainlab.Translate in the backend from PHP, use the following code:

use RainLab\Translate\Models\Message;

// use Rainlab's Message translation
$translated = Message::trans('key');

If you need to translate something with Laravel default translation in the backend from PHP, use the following code:

// use default Laravel helper function
$translated = trans('key');

The current locale will be used.

Discussion

1 comment

0
XL1034
Post on August 28th, 2020 10:06 AM

Thank you! It's very helpful. And comment must be at least 50 characters.

We use cookies to measure the performance of this website. Do you want to accept these cookies?