Search code examples
symfonytwigsymfony4icu

Symfony4 pluralization on translation not working


Pluralization is working partially in Symfony4.3 when I use the new ICU Format for messages.

Expected behaviour: One item found

Current behaviour: {1, plural, =0 {No items found.} one {One item found.} other {# items found.} }

Translation file works for other translations, so configuration I think is right. In translations/messagges.en.yaml

msg:
    photos:
        uploaded: >
            {photos, plural,
                =0 {No items found.}
                one {One item found.}
                other {# items found.}
            }

And in the template there is the following line:

{{ 'msg.photos.uploaded'|trans({'photos': 1}) }}

Solution

  • I believe, for the ICU message format to work, the filename must be correct (more precisely, the domain must have +intl-icu appended):

    https://symfony.com/doc/current/translation/message_format.html#using-the-icu-message-format

    in your case, the filename should be: translations/messages+intl-icu.en.yaml according to the source above.