Posted By

vas3k on 09/09/09


Tagged

python django


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

sapphiriq


Django: Pluralize templatetag for Russian lang


 / Published in: Python
 

  1. # -*- coding: utf-8 -*-
  2. from django import template
  3.  
  4. register = template.Library()
  5.  
  6. @register.filter
  7. def rupluralize(value, arg="дурак,дурака,дураков"):
  8. args = arg.split(",")
  9. if not value:
  10. return args[2]
  11. number = abs(int(value))
  12. a = number % 10
  13. b = number % 100
  14.  
  15. if (a == 1) and (b != 11):
  16. return args[0]
  17. elif (a > 1) and (a < 5) and ((b < 10) or (b > 20)):
  18. return args[1]
  19. else:
  20. return args[2]

Report this snippet  

You need to login to post a comment.