cbtr
July 1, 2021, 5:21am
#1
Hi,
I’m having trouble to use tc()
helper, in the doc the first argument can be given in string or array. But when I put an array, Kirby throws an error saying it expect a string but array were given.
If tc()
helper is a shortcut of I18n::translateCount() then the doc here is a mistake?
What I’m trying to do is to have this output:
$count result
pluralize depending on the value of $count
.
What I tried:
<?= tc(['found-result', 'found-results'], $total) =>
I agree, that seems to be an error in the tc() helper docs:
The function is supposed to be used with translation strings, see tests code:
$this->assertSame('Speichern', I18n::translate([
'en' => 'Save',
'de' => 'Speichern'
]));
}
/**
* @covers ::translateCount
*/
public function testTranslateCount()
{
I18n::$translations = [
'en' => [
'car' => ['No cars', 'One car', 'Two cars', 'Many cars']
]
];
$this->assertSame('No cars', I18n::translateCount('car', 0));
$this->assertSame('One car', I18n::translateCount('car', 1));
$this->assertSame('Two cars', I18n::translateCount('car', 2));
cbtr
July 1, 2021, 8:05am
#3
Thank you @texnixe for the answer, that’s what I have now and it’s working.
I18n::translateCount('result', $total);
In the translation file (en.php):
'result' => ['No result', '{{ count }} results'],