vslavik / poedit

Translations editor for Mac, Windows and Unix
https://poedit.net
MIT License
1.79k stars 278 forks source link

Symphony Twig pluralization has changed #736

Open withinboredom opened 2 years ago

withinboredom commented 2 years ago

With the deprecation of https://github.com/twigphp/Twig-extensions and switching over to https://github.com/symfony/twig-bridge, it appears Symfony has subtly drastically changed how pluralization works.

Former:

{% trans %}
  singular
{% plural count_var %}
  plural
{% endtrans %}

Now:

{% trans count count_var %}
singular|plural
{% endtrans %}

Is there anyway that poedit can recognize the | to delineate the singular/plural form?

This is not well documented at all by them, and I had to go digging into the parser to figure out how to make it work 😂

vslavik commented 2 years ago

This is not well documented at all by them

That makes it somewhat hard to support… Even your example is a bit ambiguous (count and count_var are intentional or a typo, and if not, mean what?).

withinboredom commented 2 years ago

That makes it somewhat hard to support…

And just as annoying to use. :joy: It doesn't help that they have the issue tracker disabled too. For plurals, I'll probably just end up passing it as a template variable and have regular gettext do the translating in PHP.

count and count_var are intentional or a typo, and if not, mean what?

count is an attribute, it will always be count while count_var is a variable holding the current count.

vslavik commented 2 years ago

Would you have some example files? I can't find any in their repository...

withinboredom commented 2 years ago

I managed to find some examples in their unit tests:

https://github.com/symfony/twig-bridge/blob/5.4/Tests/Extension/TranslationExtensionTest.php#L79-L108

Jesus. Now a bit of the parser makes sense. It looks like if there is just a %count% variable in the text, it will use that as the count. This is a strange syntax: ]1,Inf] which I imagine is some way to say from 1 (exclusive) to infinity (inclusive). Shame they literally don't document this anywhere, I'll have to experiment with it.

ArnaudLigny commented 2 years ago

Here is a full example of the syntax:

{0}I don't have apples|{1}I have one apple|]1,Inf[I have %count% apples

More details in the Sf documentation: https://symfony.com/doc/5.4/translation.html#message-format

vslavik commented 2 years ago

More details in the Sf documentation: https://symfony.com/doc/5.4/translation.html#message-format

There aren't more details there, though. This one limited example is literally all there is written on the subject of non-ICU formatting.

mjac commented 2 years ago

Here's the latest version of their test following up on @withinboredom: https://github.com/symfony/twig-bridge/blob/6.1/Tests/Extension/TranslationExtensionTest.php

There is a lot of information in the comments of this class: https://github.com/symfony/contracts/blob/main/Translation/TranslatorInterface.php