Repository navigation
[13.x] Fix trans_choice() picking the wrong plural form for negative numbers - #61700
Merged
taylorotwell merged 1 commit intoSep 24, 2026
Merged
taylorotwell merged 1 commit into
taylorotwell merged 1 commit into
Conversation
getPluralIndex() compared the signed number against every rule, so
negative counts always fell through to the last form ("-1 items" in
English, the genitive plural for -1 or -2 in Russian). CLDR plural
operands use the absolute value, and Symfony's copy of these rules
already calls abs(). Explicit ranges like {-1} are matched before the
rules and are unaffected.
Contributor
|
Does this apply to every language? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
MessageSelector::getPluralIndex()checks the signed number against each locale's rule, so negative counts fall through to the last form:This shows up with things like balance or score changes ("-1 point"). CLDR defines the plural operands on the absolute value of the number, and Symfony's copy of the same rule table already calls
abs($number)before matching.This applies
abs()to numeric values only, sonullor non-numeric strings get the same result as before instead of a deprecation or TypeError. Explicit ranges like{-1}are matched inextract()before the plural rules run, so they're unaffected (#58648).