Opened 13 years ago

Last modified 12 years ago

#17632 closed New feature

new filter for localflavor 'The Netherlands' — at Initial Version

Reported by: lkeijser Owned by: nobody
Component: contrib.localflavor Version: 1.3
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: yes
Needs tests: yes Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I've created a small filter that can be used in the same way as 'pluralize'. It basically adds 'en' (most common pluralized word in Dutch) when used.


from django import template
from django.template.defaultfilters import stringfilter

register = template.Library()

@register.filter
def meervoud(value, arg=u'en'):

if not u',' in arg:

arg = u',' + arg

bits = arg.split(u',')
if len(bits) > 2:

return u

singular_suffix, plural_suffix = bits[:2]

try:

if int(value) != 1:

return plural_suffix

except ValueError: # Invalid string that's not a number.

pass

except TypeError: # Value isn't a string or a number; maybe it's a list?

try:

if len(value) != 1:

return plural_suffix

except TypeError: # len() of unsized object.

pass

return singular_suffix


Change History (0)

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