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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

elky’s picture

Status: Active » Needs review
FileSize
777 bytes
Damien Tournoud’s picture

Version: 7.x-dev » 8.x-dev
Status: Needs review » Needs work

Not 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.

shravan sonkar’s picture

Issue summary: View changes
Status: Needs work » Needs review
Issue tags: +#SprintWeekend2015
FileSize
11.07 KB

fixed

shravan sonkar’s picture

David Hernández’s picture

Issue tags: -#SprintWeekend2015 +SprintWeekend2015

Hello!

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 #.

Mile23’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll

Cursory 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 the string_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.

alvar0hurtad0’s picture

Status: Needs work » Needs review
FileSize
0 bytes

According to #6 this is the fix to check if positive.

Status: Needs review » Needs work

The last submitted patch, 7: format_plural_returns_a-1131926-7.patch, failed testing.

alvar0hurtad0’s picture

Sorry, last patch uploaded empty

lokapujya’s picture

-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.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Vacilando’s picture

Assigned: Unassigned » Vacilando
Vacilando’s picture

Version: 8.2.x-dev » 8.3.x-dev
Issue tags: -Needs reroll +Dublin2016

Too late for 8.2.x; changing the core version to 8.3.x. and queueing a test for that branch.

Vacilando’s picture

Test OK — patch #9 works as expected for 8.3.x.

Vacilando’s picture

Assigned: Vacilando » Unassigned

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

mondrake’s picture

#9 still passes after 3 years!

#10: IMO this issue is legitimate. See #3001398-5: format_size() fixes

What if you had a diff system that as well as showing the changes in lines it showed the change in filesize? That could be a negative value.

So you may want to display "File bingo-bongo.txt size diff is -1 byte."

This needs tests, NW for that.

googletorp’s picture

Status: Needs work » Needs review
FileSize
656 bytes
1.28 KB

To 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.

Status: Needs review » Needs work

The last submitted patch, 22: 1131926-22.patch, failed testing. View results

googletorp’s picture

Status: Needs work » Needs review

Retesting patch, looks like some issue with Selenium server caused fail, even though all tests was passed.

mondrake’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs tests

Thank you! RTBC

alexpott’s picture

Status: Reviewed & tested by the community » Needs review

I 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 word against. 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.

alexpott’s picture

We 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.

googletorp’s picture

Issue summary: View changes
alexpott’s picture

@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:

-1 = negative one apples (uncountable, you can't have negative of something real, like money. This is a mathematical concept only, hence plural would be OK.) This feels like negative-one apples

alexpott’s picture

I 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.

mondrake’s picture

Besides the linguistic debate, I am afraid we have a more immediate problem looking at the guidance given for PluralTranslatableMarkup arguments:

  /**
   * Constructs a new PluralTranslatableMarkup object.
   *
   * Parses values passed into this class through the format_plural() function
   * in Drupal and handles an optional context for the string.
   *
   * @param int $count
   *   The item count to display.
   * @param string $singular
   *   The string for the singular case. Make sure it is clear this is singular,
   *   to ease translation (e.g. use "1 new comment" instead of "1 new"). Do not
   *   use @count in the singular string.
   * @param string $plural
   *   The string for the plural case. Make sure it is clear this is plural, to
   *   ease translation. Use @count in place of the item count, as in
   *   "@count new comments".
   * @param array $args
   *   (optional) An array with placeholder replacements, keyed by placeholder.
   *   See \Drupal\Component\Render\FormattableMarkup::placeholderFormat() for
   *   additional information about placeholders. Note that you do not need to
   *   include @count in this array; this replacement is done automatically
   *   for the plural cases.
   * @param array $options
   *   (optional) An associative array of additional options. See t() for
   *   allowed keys.
   * @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation
   *   (optional) The string translation service.
   *
   * @see \Drupal\Component\Render\FormattableMarkup::placeholderFormat()
   */

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.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

mondrake’s picture

Status: Needs review » Closed (won't fix)

Sounds like won't fix ATM. Anybody feel free to reopen if more arguments.