Opened 17 years ago

Closed 17 years ago

Last modified 17 years ago

#2202 closed enhancement (fixed)

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

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

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@…> 17 years ago.
optional_arguments_to_pluralize.patch (2.1 KB) - added by Chris Beaven 17 years ago.
Pluralize with optional arguments (tests and documentation included)

Download all attachments as: .zip

Change History (10)

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

comment:1 Changed 17 years ago by (none)

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 17 years ago by Adrian Holovaty

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 17 years ago by anonymous

Owner: changed from Adrian Holovaty to anonymous
Status: newassigned

comment:4 Changed 17 years ago by Adrian Holovaty

Owner: changed from anonymous to Adrian Holovaty
Status: assignednew

comment:5 Changed 17 years ago by Adrian Holovaty

Status: newassigned

Changed 17 years ago by Chris Beaven

Pluralize with optional arguments (tests and documentation included)

comment:6 Changed 17 years ago by Chris Beaven

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

comment:7 Changed 17 years ago by Russell Keith-Magee

Resolution: fixed
Status: assignedclosed

(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 17 years ago by Russell Keith-Magee

(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