Radical Design Course by Jack McDade

From the creator of Statamic

Learn how to make your websites standout and be remembered.

For a software dev like me who has no idea how to create a cute hand-drawn dashed line, this course just 100% works.

— Ira Zayats, Developer

Translate Tag

Retrieve a string from a language file in the current locale.

This tag is the equivalent of the trans and trans_choice methods provided by Laravel.

Hot Tip!

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).

<?php
return [
'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

tagpart|string

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

string

The locale to be used when translating.

any parameters

string

Any additional parameters will be treated as parameters that should be replaced in the string.

count

integer *1*

When using trans_choice, this is the number that defines the pluralization.

Docs feedback

Submit improvements, related content, or suggestions through Github.

Betterify this page →