← Back to Course

Using the trans() and Lang::get() Methods

Laravel provides two main ways to retrieve a translated string: the trans() helper function and the Lang facade — both read from the same underlying language files.

Using trans()

echo trans('messages.welcome');

In Blade views, the shorthand @lang directive or the __() helper are commonly used instead:

{{ __('messages.welcome') }}

Using Lang::get()

echo Lang::get('messages.welcome');

Lang::get() and trans() are functionally equivalent — trans() is simply a convenient global wrapper around the Lang facade.

Passing Placeholders

// lang/en/messages.php
'greeting' => 'Hello, :name!',
echo trans('messages.greeting', ['name' => 'Ravi']);

Handling Pluralization

'apples' => '{0} No apples|{1} One apple|[2,*] :count apples',
echo trans_choice('messages.apples', $count);

Retrieving strings is only half the picture — keeping the underlying language files organized as an app grows in size and language count is just as important.

Ready to master Laravel Training Course?

Join Uncodemy's hands-on Laravel program and build real, production-ready applications.

Explore Course