This tag is the equivalent of the trans and trans_choice methods provided by Laravel.
There's also a modifier 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).
<?phpreturn [ 'bar' => 'Bar!', 'welcome' => 'Welcome, :name!', 'apples' => 'There is one apple|There are :count apples',];
{{ trans:foo.bar }} or {{ trans key="foo.bar" }}
{{ trans('foo.bar') or {{ __('foo.bar') }}
Bar!
Replacements
Any additional tag parameters will be treated as parameters that should be replaced in the string.
{{ trans:foo.welcome name="Bob" }}
{{ trans('foo.welcome', ['name' => 'Bob']) }}
Welcome, Bob!
Pluralization
To pluralize, use the trans_choice
tag with a count
parameter.
{{ trans_choice:foo.apples count="2" }}
{{ trans_choice('foo.apples', 2) }}
There are 2 apples
Parameters
key
The key of the translation string to find. Include both the filename and string key delimited with dots. Can be used as a tag part or a key
parameter. If your key contains a namespace, you should use the key parameter instead of the tag part.
locale|site
The locale to be used when translating.
any parameters
Any additional parameters will be treated as parameters that should be replaced in the string.
count
When using trans_choice
, this is the number that defines the pluralization.