#20122: Pluralize filter sometimes returns singular form instead of an empty string for invalid inputs --------------------------------------+------------------------------------ Reporter: aaugustin | Owner: nobody Type: Cleanup/optimization | Status: new Component: Template system | Version: master Severity: Normal | Resolution: Keywords: | Triage Stage: Accepted Has patch: 0 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 0 Easy pickings: 0 | UI/UX: 0 --------------------------------------+------------------------------------
Comment (by littlepig): I don't agree with the suggested implementation because when you pass a string to a pluralize it should not assume the string can be "pluralized". In your case, if you pass 'one', it would return the plural, and I think that it should return an empty string: it is language dependent whether strings represent singular or plural number. One possible solution that compromises both cases: {{{ if value == 1 or value == u'1': return singular try: float(value) return plural except ValueError: # a string that cannot be parsed as a float and thus is an undefined number return '' }}} This avoids the {{{isinstance()}}} and also corrects the pluralization of floats (1 unit but 1.1 units). Cheers, Jorge -- Ticket URL: <https://code.djangoproject.com/ticket/20122#comment:2> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To post to this group, send email to django-updates@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/067.c616768c9bcc83d571eb8f3146aa0c61%40djangoproject.com?hl=en. For more options, visit https://groups.google.com/groups/opt_out.