K. Weber
K. Weber

Reputation: 2773

Plurals in Twig Symfony 5

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?

Upvotes: 1

Views: 4303

Answers (1)

craigh
craigh

Reputation: 2291

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

Upvotes: 3

Related Questions