How to use fbt::param with fbt::plural?

Viewed 30

I use FBT package (4.0.5) for PHP. I need a parameter inside a plural. I would like to display the show name only if it is singular, otherwise I would like to display it as a plural. Like this:

Stranger Things was published
Stranger Things and 3 other series were published

I tried this:

<?php

echo fbt(
  \fbt\fbt::plural(
    \fbt\fbt::param('show name', 'Stranger Things') . ' was published',
    3,
    [
      'name' => 'number of series',
      'showCount' => 'ifMany',
      'many' => 'series were published',
    ]
  ),
  'Label for number of published series'
);

But this error is thrown:

fbt:plural expects text or an expression, and only one
---
<fbt:plural count="3" name="number of series" showCount="ifMany" many="series were published" implicitDesc="[show name] was published"><fbt:param name="show name">Stranger Things</fbt:param> was published</fbt:plural>
---
1 Answers

How awesome to see my work on StackOverflow!

For this case, I suggest using if/else:

<?php

$count = 3;

if ($count === 1) {
    echo fbt(
        \fbt\fbt::param('show name', 'Stranger Things') . ' was published',
        'Label for the published show'
    );
} else {
    echo fbt(
        [
            \fbt\fbt::param('show name', 'Stranger Things') . ' and ',
            \fbt\fbt::param('number of series', (string)$count) . ' other series were published',
        ],
        'Label for number of published series'
    );
}
Related