Modifier: trans

Retrieve a string from a language file in the current locale. It is the equivalent of the trans and trans_choice methods provided by Laravel.

There’s also a tag version that you may prefer.

Usage

Get the bar string from the resources/lang/en/foo.php translation file (where en is the current locale).

<?php
return [
    'bar' => 'Bar!',
    'welcome' => 'Welcome, :name!',
    'apples' => 'There is one apple|There are :count apples',
];
key: 'foo.bar'
this_many: 2
{{ key | trans }} or {{ "foo.bar" | trans }}
Bar!

Replacements

Parameter replacements are only supported in the tag version.

Pluralization

To pluralize, use the trans_choice modifier with the count as the parameter. You can use a number or a variable.

{{ "foo.apples" | trans:2 }}
{{ "foo.apples" | trans:this_many }}
There are 2 apples

Strings

As you can see above, you may use the modifier on inline strings. Instead of translation keys, you can use simple strings. These will be referenced from resources/lang/fr.json (where fr is the locale).

{
  "Hello": "Bonjour"
}
{{ "Hello" | trans }}
Bonjour
Betterify this page on Github!