Trans Modifier
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.
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 }}
{{ trans($key) }} {{ trans('foo.bar') }}
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_choice(2) }}
{{ "foo.apples" | trans_choice($this_many) }}
{{ trans_choice('foo.apples', 2) }}
{{ trans_choice('foo.apples', $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 }}
{{ trans('Hello') }}
Bonjour
Docs Feedback
Submit improvements, related content, or suggestions through Github.
Betterify this page