Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Symphony Twig pluralization has changed #736

Open
withinboredom opened this issue Feb 20, 2022 · 7 comments
Open

Symphony Twig pluralization has changed #736

withinboredom opened this issue Feb 20, 2022 · 7 comments

Comments

@withinboredom
Copy link

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
Copy link
Owner

vslavik commented Feb 22, 2022

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
Copy link
Author

That makes it somewhat hard to support…

And just as annoying to use. 😂 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
Copy link
Owner

vslavik commented Feb 22, 2022

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

@withinboredom
Copy link
Author

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
Copy link

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 vslavik changed the title Twig pluralization has changed Symphony Twig pluralization has changed Sep 7, 2022
@vslavik
Copy link
Owner

vslavik commented Oct 19, 2022

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
Copy link

mjac commented Oct 20, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants