Outputting a Translation in a Blade Template

Problem

You want to use translations in your Blade template.

Solution

Use the Blade @lang command.

For example:

@lang('messages.welcome')

Assuming there's a welcome key in the messages.php for the current locale, the above would output the translated message.

If there is no translated message then messages.welcome would be output.

If your message has a placeholder, you can pass a second parameter with an array of placeholders.

@lang('messages.welcome', ['name' => $name])

Discussion

This Blade command uses the Lang::get() method.

See Getting the Translation for a Key for details about this method.

comments powered by Disqus