Skip to content

Instantly share code, notes, and snippets.

@patrys
Created October 5, 2010 13:47
Show Gist options
  • Save patrys/611569 to your computer and use it in GitHub Desktop.
Save patrys/611569 to your computer and use it in GitHub Desktop.
{% load liczba_mnoga %}
<p>{% liczba_mnoga user_count "jedna osoba" "%(n)s osoby" "%(n)s osób" %}</p>
from django import template
register = template.Library()
@register.simple_tag
def liczba_mnoga(n, form1, form2, form5):
n = abs(n)
if n == 1:
return form1 % {'n': n}
if n % 10 >= 2 \
and n % 10 <= 4 \
and (n % 100 < 10 or n % 100 >= 20):
return form2 % {'n': n}
return form5 % {'n': n}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment