Code

Opened 5 years ago

Closed 16 months ago

#12380 closed Uncategorized (invalid)

Shouldn't the pluralize filter consider 0 to be singular?

Reported by: aleray Owned by: nobody
Component: Template system Version: 1.5
Severity: Normal Keywords: pluralize templatetag
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Shouldn't the pluralize filter consider 0 to be singular?

Consider this example:

{% get_comment_count for paragraph as comment_count %}
{{ comment_count }} comment{{ comment_count|pluralize }}

For instance if comment_count is equal to 0, the output will be "0 comments" (with a final s).

Attachments (0)

Change History (4)

comment:1 Changed 5 years ago by anonymous

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

comment:2 Changed 5 years ago by kmtracey

  • Resolution set to invalid
  • Status changed from new to closed

No, in English zero uses the plural form, see:

http://en.wikipedia.org/wiki/Plural#Zero

The current behavior is correct and documented:

http://docs.djangoproject.com/en/dev/ref/templates/builtins/#pluralize

The only value that does not get the plural suffix is 1.

comment:3 Changed 16 months ago by etienned

  • Component changed from Contrib apps to Template system
  • Easy pickings unset
  • Resolution invalid deleted
  • Severity set to Normal
  • Status changed from closed to new
  • Type set to Uncategorized
  • UI/UX unset
  • Version changed from 1.1 to 1.5

And what about other languages such as French where the plural form is not use for zero (see Wikipedia article)? Maybe pluralize should take into account the active language and do the right thing for each language? I know this is not simple.

comment:4 Changed 16 months ago by claudep

  • Resolution set to invalid
  • Status changed from new to closed

I think that pluralize is mainly targeted to the English language. For any other language, you are probably better off creating your own specialized filter. You can then propose it as an external app or even as part of a localflavor.

Please discuss it on django-dev first, and if a real solution emerges, then reopen the ticket.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.