Plurals in Twig Symfony 5

Viewed 2205

As of Twig 3.x the filter transchoice is deprecated, I'm trying to figure out how is the proper syntax for twig, as docs are centered in php syntax.

This is my messages.en.yml file:

client: >-
            {number, plural,
                one {Client}
                other {Clients}
            }

And this is my twig template, trying to figure out what it should be according to this doc:

{{"client"|trans({'number': 2})}}

The result is this string, this is, the variable number is not being processed:

{2, plural, one {Client} other {Clients} }

So, what is the correct syntax to see only Client or Clients depending on number?

1 Answers

Structuring your translation that way is using the ICU Message Format. In order to use the ICU Message Format, the message domain file has to be suffixed with +intl-icu.

Make sure you name your file correctly:

translations/messages+intl-icu.en.yaml
Related