Django: Pluralize templatetag for Russian lang


/ Published in: Python
Save to your folder(s)



Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.