tc()
Translates a count
tc(string $key, int $count, string|null $locale = null, bool $formatNumber = true): mixed
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| $keyrequired | string |
no default value | |
| $countrequired | int |
no default value | |
| $locale | stringornull |
null
|
|
| $formatNumber | bool |
true
|
If set to false, the count is not formatted |
Return type
mixed
Examples
Given a translation with a placeholder. You can define the translation as an array for different counts.
'translations' => [
'en' => [
'errors' => ['There are no errors', 'There is { count } error.', 'There are { count } errors.'],
],
// …
],
Replace placeholder with given number.
echo tc('errors', 0);
// There are no errors.
echo tc('errors', 1);
// There is 1 error.
echo tc('errors', 5);
// There are 5 errors.