Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
If format_plural() is passed a count of -1, it evaluates it as a plural.
There is not 100% agreement about how to -1, but the far majority favors treating -1 as a singular value. One example could be account balance:
Balance: -1 dollar vs Balance: -1 dollars
This can be circumvented in some cases by changing wording for negative numbers, but we should still treat the use of -1 correctly.
Comment | File | Size | Author |
---|---|---|---|
#22 | 1131926-22.patch | 1.28 KB | googletorp |
#22 | 1131926-22-test-only.patch | 656 bytes | googletorp |
Comments
Comment #1
elky CreditAttribution: elky commentedComment #2
Damien Tournoud CreditAttribution: Damien Tournoud commentedNot sure what to do with the negative numbers. Gettext itself only supports positive numbers, and has some discussion about negative and floating point numbers (suggesting to treat them as plural... which does not really solve the translation issue).
Also, some people seem to say that s"minus one" should be plural, as in "minus one apples".
Whatever we do, this seems to be a larger subject then just the
$count == 1
, so marking as needs work for now.Comment #3
shravan sonkar CreditAttribution: shravan sonkar commentedfixed
Comment #4
shravan sonkar CreditAttribution: shravan sonkar commentedComment #5
David Hernández CreditAttribution: David Hernández commentedHello!
Thank you for working on this issue!
We should all try and use the same sprint tag. According to https://groups.drupal.org/node/447258 it should be SprintWeekend2015 with no #.
Comment #6
Mile23Cursory examination says this issue is still outstanding in D8.
Here's a change record about
format_plural()
: https://www.drupal.org/node/2173787 Basically it's part of thestring_translation
service now.There's an existing test here:
Drupal\locale\Tests\LocalePluralFormatTest::testGetPluralFormat()
which seems to test for negative values, but the inline documentation makes it hard to tell.The actual substitution is done in
Drupal\Core\StringTranslation\PluralTranslatableMarkup::render()
.Marking this as needs reroll, even though it's really more of a refactor.
Comment #7
alvar0hurtad0According to #6 this is the fix to check if positive.
Comment #9
alvar0hurtad0Sorry, last patch uploaded empty
Comment #10
lokapujya-1 should remain plural. If you want it to be singular then you should pass in the absolute value to format_plural()
besides, "-1 vote(s) against" is a double negative and so the minus symbol probably shouldn't be displayed.
Comment #13
Vacilando CreditAttribution: Vacilando as a volunteer commentedComment #14
Vacilando CreditAttribution: Vacilando as a volunteer commentedToo late for 8.2.x; changing the core version to 8.3.x. and queueing a test for that branch.
Comment #15
Vacilando CreditAttribution: Vacilando as a volunteer commentedTest OK — patch #9 works as expected for 8.3.x.
Comment #16
Vacilando CreditAttribution: Vacilando as a volunteer commentedComment #21
mondrake#9 still passes after 3 years!
#10: IMO this issue is legitimate. See #3001398-5: format_size() fixes
So you may want to display "File bingo-bongo.txt size diff is -1 byte."
This needs tests, NW for that.
Comment #22
googletorp CreditAttribution: googletorp as a volunteer and at Reveal IT commentedTo me it's crazy that some so simple has been sitting for 3 years without getting committed.
So I added test case for this, fixed a code standards issue in the original patch and supplied a test only and final patch for this.
Regarding if -1 should be plural or singular - there is a long read here: https://english.stackexchange.com/questions/9735/is-1-followed-by-a-sing...
The short version is comparing a text like:
"Account ballance: -1 dollar" and "Account ballance: -1 dollars".
The general consensus seems to be that the amount of 1 (regardless of positive or negative) is singular.
Comment #24
googletorp CreditAttribution: googletorp as a volunteer and at Reveal IT commentedRetesting patch, looks like some issue with Selenium server caused fail, even though all tests was passed.
Comment #25
mondrakeThank you! RTBC
Comment #26
alexpottI agree with #10 / @lokapujya. The example in the issue summary feels a bit weird as I would expect it to be
1 vote for, 1 votes against
and the caller to make the number absolute since the negativity is conveyed by the wordagainst
. I think it is quite rare to call PluralTranslatableMarkup with a negative number - since normally with countable things you don't have - of them. Ie. you don't have -1 vote against, you have 1 vote against.I think we could improve the documentation to suggest the $count should be a positive number and maybe deprecate calling this with negative numbers - unless we can come up with some better examples. An example of negative votes I can think of on the internet is arstechnica's +/- system of votes on comments but they don't put any words around that.
Comment #27
alexpottWe also need to check that this logic would make sense for other languages. I think it does in english but I'm not sure, thinking about -1 apple hurts my brain.
Comment #28
googletorp CreditAttribution: googletorp as a volunteer and at Reveal IT commentedComment #29
alexpott@googletorp you're right that balance is a much better example. However, for me I feel that
-1 pounds
is better then-1 pound
- there is not a real consensus on the stack exchange article you point to.For example it says:
Comment #30
alexpottI guess what I'm saying is that it depends on the context whether using the plural or singular form is correct so picking one over the over is never going to be write for all cases. So I think we need to encode whether to use singular or plural forms into the string itself because then different languages can encode this differently as it is highly likely that the rules are completely different for different languages.
Comment #31
mondrakeBesides the linguistic debate, I am afraid we have a more immediate problem looking at the guidance given for
PluralTranslatableMarkup
arguments:The fact that we are saying "Do not use @count in the singular string." means that we are unable to print out the negative singular, or that we have a string that may be out of context.
Changing to use @count means most if not all singular strings would need to be changed and translated.
I think this is a won't fix as there won't be a one-fits-all solution.
Special use cases for negative singular should probably be dealt with by calling code, like the '-1 byte' vs '-1 bytes' case being discussed at #3001398: format_size() fixes.
Comment #36
mondrakeSounds like won't fix ATM. Anybody feel free to reopen if more arguments.