Last active
March 5, 2018 04:25
-
-
Save xfenix/4761104 to your computer and use it in GitHub Desktop.
Russian pluralize django template tag
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# pluralize for russian language | |
# {{someval|rupluralize:"товар,товара,товаров"}} | |
@register.filter(is_safe = False) | |
@stringfilter | |
def rupluralize(value, arg): | |
bits = arg.split(u',') | |
try: | |
value = str( 0 if not value or value <= 0 else value )[-1:] # patched version | |
return bits[ 0 if value=='1' else (1 if value in '234' else 2) ] | |
except: | |
raise TemplateSyntaxError | |
return '' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Этот код ошибочный. Например, вместо "14 домов" он выдаст "14 дома".
Вот правильная версия: https://gist.github.com/dpetukhov/cb82a0f4d04f7373293bdf2f491863c8