#21650: Usage example in i18n docs is bad advice for plurals --------------------------------------+------------------------------------ Reporter: nedbatchelder | Owner: nobody Type: Cleanup/optimization | Status: new Component: Documentation | Version: 1.6 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 --------------------------------------+------------------------------------
Old description: > This example in the i18n docs: > > {{{ > Lets see a slightly more complex usage example:: > > from django.utils.translation import ungettext > from myapp.models import Report > > count = Report.objects.count() > if count == 1: > name = Report._meta.verbose_name > else: > name = Report._meta.verbose_name_plural > > text = ungettext( > 'There is %(count)d %(name)s available.', > 'There are %(count)d %(name)s available.', > count > ) % { > 'count': count, > 'name': name > } > }}} > > Here we choose between two forms of name (singular and plural) based on > whether the count is 1 or not. That is the rule in English, but not in > other languages. The whole point of ungettext is to defer the logic that > performs the mapping from number to text, since it depends on the > language. > > Unfortunately, I think the only solution is to use more stilted language: > > {{{ > text = ungettext( > 'There is %(count)d %(name)s object available.', > 'There are %(count)d %(name)s objects available.', > count > ) % { > 'count': count, > 'name': Report._meta.verbose_name, > } > }}} > > and ignore the verbose_name_plural altogether. New description: [https://docs.djangoproject.com/en/dev/topics/i18n/translation/#pluralization This example in the i18n docs]: {{{ Lets see a slightly more complex usage example:: from django.utils.translation import ungettext from myapp.models import Report count = Report.objects.count() if count == 1: name = Report._meta.verbose_name else: name = Report._meta.verbose_name_plural text = ungettext( 'There is %(count)d %(name)s available.', 'There are %(count)d %(name)s available.', count ) % { 'count': count, 'name': name } }}} Here we choose between two forms of name (singular and plural) based on whether the count is 1 or not. That is the rule in English, but not in other languages. The whole point of ungettext is to defer the logic that performs the mapping from number to text, since it depends on the language. Unfortunately, I think the only solution is to use more stilted language: {{{ text = ungettext( 'There is %(count)d %(name)s object available.', 'There are %(count)d %(name)s objects available.', count ) % { 'count': count, 'name': Report._meta.verbose_name, } }}} and ignore the verbose_name_plural altogether. -- Comment (by timo): I don't use i18n, but Ned's suggest seems reasonable to me. Claude, what do you think? My only question would be what modifications to make to the note that follows. Currently it says, "When using this technique", and my understanding is that we'd be changing things to say not to use this technique. I think the note still has value though as it's linked to from elsewhere. -- Ticket URL: <https://code.djangoproject.com/ticket/21650#comment:5> 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/071.55c395e8f0279d6eb61da19a392fb35b%40djangoproject.com. For more options, visit https://groups.google.com/groups/opt_out.