-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Translation] Floating number plural broken #30215
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
Comments
Here are some additional sources: All I find tend to define 1.5 as plural in English but Symfony no longer do (it was the cas before the typing was added). |
Your use case only used to work accidentally based on the fact that we were not able to use scalar type hints on older Symfony versions. The count value always was expected to be an integer. Decimals are currently not supported. |
Before the typing, rules != 1 (English) and <2 (French) were accurate and able to work with floats. Nothing specified decimals were not supported and as far as I know, there were no bugs with floats. So despite it worked accidentally, forcing integer and limit the support to integers was actually a regression. So unless float causes real problems. It should not be forbidden. If some pluralization rules does not support them, so those specific rules could have Do you want me to propose a PR? |
The interface defined that the number had to be an integer: symfony/src/Symfony/Component/Translation/TranslatorInterface.php Lines 37 to 50 in 13d1d76
Since I have no idea if this works for all supported I would not be in favour of adding this feature. |
You can put the Then it can be fixed language per language afterward and it will allow custom plural rule that would now be able to handle floating numbers. Having correct plural in English seems an important concern for such a great project. Sounds a bit weird to say to symfony users: "Don't use decimal numbers if you wish a correct pluralization".
Not a reason. This can be tested. I can add tests for 0.5, 1.5 and 2.5 in each language then fix the typing and see what languages changed, so we can check for each language in grammar reference if we have to fix it (as the English plural) or keep the previous rule by forcing |
Is this a regression or did it always work that way? |
@nico-incubiq, it's the result for symfony 4.2, |
For the record, plural in French starts at 2. So, it's "2 litres" but "1.5 litre". So, nothing is obvious when it comes to languages :) |
Yes @fabpot it's exactly the point. Singular in French is Those rules include decimal numbers, so you can't be accurate using NB: |
The question is, does ICU define rules for floating numbers too ? If no, the ICU-based formatting would not help anyway and it is the new recommended default. |
Yes it does (as long as you use groups "few, one, other" of course and not explicit values), this format is used in Angular, and Angular handle properly the plural of 1.5 in French and in English. 1.5 is "one" in French. As simple. |
Hey, thanks for your report! |
No workaround possible, we sill have no way to properly pluralize sentences with floating numbers such as translating "1.5 liters" in English into "1.5 litre" in French. |
I just tested this issue, with translations in ICU format, and I do not find the bug. {{ 'product.carats'|trans({ 'carat': 1.2 }) }} With this translation: <unit id="zcajhWf" name="product.carats">
<segment>
<source>product.carats</source>
<target>{carat, plural,
one {Weight: # carat}
other {Weight: # carats}
}</target>
</segment>
</unit> The output is correct:
|
The buggy code is still there:
You need to pass through this method to get the bug and you need 2 languages with different floating pluralization rules. As long as |
@kylekatarnls would you mind working on a fix please? That's a bugfix for branch 4.4. |
Yes, you can assign it to me :) |
Fix #39887 submitted. |
…ekatarnls) This PR was squashed before being merged into the 4.4 branch. Discussion ---------- [Translator] fix handling plural for floating numbers | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #30215 | License | MIT Commits ------- 533cd7e [Translator] fix handling plural for floating numbers
Symfony version(s) affected: 4.2.3
Description
Decimal number between 1 and 2 produces incorrect plural in English.
How to reproduce
It outputs:
It should output:
Possible Solution
int typing here should be removed, it's a float, numbers should not be truncated:
symfony/src/Symfony/Component/Translation/IdentityTranslator.php
Line 57 in 32aa969
Related to #16256
The text was updated successfully, but these errors were encountered: