Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#2202 closed enhancement (fixed)

[patch] Added optional argument to template filter "pluralize"

Reported by: gid <setre3+django@…> Owned by: adrian
Component: Template system Version: master
Severity: minor Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

Makes the following valid in a template: {{ tomatoes|pluralize:"es" }}

Attachments (2)

optional_argument_to_pluralize_template_filter.diff (905 bytes) - added by gid <setre3+django@…> 9 years ago.
optional_arguments_to_pluralize.patch (2.1 KB) - added by SmileyChris 9 years ago.
Pluralize with optional arguments (tests and documentation included)

Download all attachments as: .zip

Change History (10)

Changed 9 years ago by gid <setre3+django@…>

comment:1 Changed 9 years ago by anonymous

I dunno. The pluralize filter is a bad hack - it can't handle cases where the plural isn't formed by tacking something onto the end of the singular, e.g. man/men or knife/knives. There's a fair few of these cases in English, and it's the default in many languages.

AFAIK you can't pass more than one extra argument to a filter, so I don't think pluralize is fixable. If you care at all about grammatical correctness, you probably shouldn't be using it.

comment:2 Changed 9 years ago by adrian

The pluralize filter is a very simple 80% solution. This patch makes it more of an 85% solution, which I'm comfortable with. It just needs docs -- then it can be committed.

comment:3 Changed 9 years ago by anonymous

  • Owner changed from adrian to anonymous
  • Status changed from new to assigned

comment:4 Changed 9 years ago by adrian

  • Owner changed from anonymous to adrian
  • Status changed from assigned to new

comment:5 Changed 9 years ago by adrian

  • Status changed from new to assigned

Changed 9 years ago by SmileyChris

Pluralize with optional arguments (tests and documentation included)

comment:6 Changed 9 years ago by SmileyChris

This patch allows for plural/singular alternatives too, so you can have your knife/knives.

comment:7 Changed 9 years ago by russellm

  • Resolution set to fixed
  • Status changed from assigned to closed

(In [3272]) Fixes #2202 -- Added ability to customize output of pluralize filter to handle irregular cases (walrus/walruses, cherry/cherries). Thanks to gid for the suggestion and the initial patch

comment:8 Changed 9 years ago by russellm

(In [3273]) Refs #2202 -- Cleaned up technique of splitting arguments, based upon a suggestion from SmileyChris.

Note: See TracTickets for help on using tickets.
Back to Top