﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
794	A template filter that lets the user choose pluralization method	ozamosi@…	Adrian Holovaty	"The current pluralization in the default filter adds an s if it should pluralize. While this is often good for english, it is not always, and it is generally not usefull for any other language. Therefore, I wrote a custom pluralization filter that lets the template author specify what the filter should return if it should return anything at all.

Here is the diff:

{{{
Index: django/core/template/defaultfilters.py
===================================================================
--- django/core/template/defaultfilters.py      (revision 1124)
+++ django/core/template/defaultfilters.py      (arbetskopia)
@@ -408,6 +408,22 @@
             pass
     return ''

+def custompluralize(value, arg):
+    """"""Returns the arg if the value is not 1. Like above, but with
+    customizable pluralization. Good for i18n""""""
+    try:
+        if int(value) != 1:
+            return arg
+    except ValueError: # invalid string that's not a number
+        pass
+    except TypeError: # value isn't a string or a number, maybe it is a list?
+        try:
+            if len(value) != 1:
+                return arg
+        except TypeError: # len() of unsized object
+            pass
+    return ''
+
 def phone2numeric(value, _):
     ""Takes a phone number and converts it in to its numerical equivalent""
     from django.utils.text import phone2numeric
@@ -447,6 +463,7 @@
 register_filter('make_list', make_list, False)
 register_filter('phone2numeric', phone2numeric, False)
 register_filter('pluralize', pluralize, False)
+register_filter('custompluralize', custompluralize, True)
 register_filter('pprint', pprint, False)
 register_filter('removetags', removetags, True)
 register_filter('random', random, False) 
}}}"	defect	closed	Template system		minor	wontfix			Unreviewed	0	0	0	0	0	0
