Skip to content

Kirby 4.5.0

tc()

Translates a count

tc(string $key, int $count, ?string $locale = null, bool $formatNumber = true): mixed|null

Parameters

Name Type Default Description
$key * string
$count * int
$locale string|null null
$formatNumber bool true If set to false, the count is not formatted

Return type

mixed|null

Example

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.