#11688: verbose_name should allow dynamical translation based on a number --------------------------------------+------------------------------------ Reporter: mitar | Owner: nobody Type: New feature | Status: reopened Component: Internationalization | Version: 1.1 Severity: Normal | Resolution: Keywords: | Triage Stage: Accepted Has patch: 1 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 1 Easy pickings: 0 | UI/UX: 0 --------------------------------------+------------------------------------
Comment (by sirex): Ofter some research, found that it is quite hard to make dynamic model names display correctly in all languages. Actually most languages divides nouns to singular, plural, numeric and grammatical case forms. Trickiest part is grammatical cases, actually most languages has same grammatical cases described here: http://en.wikipedia.org/wiki/Grammatical_case Overall there are these grammatical cases: * nominative * accusative * dative * ablative * genitive * vocative * locative * instrumental Each grammatical case has different singular, plural and numeric forms. After trying to put all this in model class, decided, that this heavily violates KISS principle, because, each model must describe all possible variations of these forms. So in my opinion, this feature must be implemented using automatically generated strings to .po files leaving models with just one verbose name: {{{ from django.db import models from django.utils.translation import Noun class Book(models.Model): title = models.CharField(max_length=128) class Meta: verbose_name = Noun('book') }}} After running {{{./manage.py makemessage -l lt}}}, these strigs must be generated: {{{ # nominative msgid "book" msgstr "knyga" msgctxt "plural" msgid "books" msgstr "knygos" msgctxt "numeric" msgid "book" msgid_plural "books" msgstr[0] "knyga" msgstr[1] "knygos" msgstr[2] "knygų" # accusative msgctxt "accusative" msgid "book" msgstr "knygą" msgctxt "accusative plural" msgid "books" msgstr "knygas" msgctxt "accusative numberic" msgid "book" msgid_plural "books" msgstr[0] "knygą" msgstr[1] "knygas" msgstr[2] "knygų" # dative msgctxt "dative" msgid "book" msgstr "knygai" msgctxt "dative plural" msgid "books" msgstr "knygoms" msgctxt "dative numberic" msgid "book" msgid_plural "books" msgstr[0] "knygai" msgstr[1] "knygoms" msgstr[2] "knygų" # ablative ... }}} Not all languages have grammatical cases and those who have, has not all of them, so I guess available grammatical cases should be listed in {{{django.conf.locale.<LANG>}}} to get smaller .po files for languages that does not have grammatical cases. Finally, instance of {{{Noun('book')}}} should work this way (all examples provided using Lithuanian language, that has all grammatical cases except ablative): 1. Singular forms: {{{ Noun('book') -> knyga Noun('book').accusative -> knygą Noun('book').dative -> knygai Noun('book').ablative -> nuo knygos Noun('book').genitive -> knygos Noun('book').vocative -> knyga Noun('book').locative -> knygoje Noun('book').instrumental -> knyga }}} 2. Plural forms: {{{ Noun('book').plural -> knygos Noun('book').plural_accusative -> knygas Noun('book').plural_dative -> knygoms Noun('book').plural_ablative -> nuo knygų Noun('book').plural_genitive -> knygų Noun('book').plural_vocative -> knygos Noun('book').plural_locative -> knygose Noun('book').plural_instrumental -> knygomis }}} 3. Numeric forms: {{{ Noun('book')[0] -> knygų Noun('book')[1] -> knyga Noun('book')[2] -> knygos Noun('book')[10] -> knygų Noun('book')[0] -> knygų Noun('book')[0].accusative -> knygų Noun('book')[0].dative -> knygų Noun('book')[0].ablative -> nuo knygų Noun('book')[0].genitive -> knygų Noun('book')[0].vocative -> knygų Noun('book')[0].locative -> knygų Noun('book')[0].instrumental -> knygų }}} In Django code, in all places must be used right noun form. For excample: {{{ {% blocktrans with cl.opts.verbose_name.accusative as name %} Add {{ name }} {% endblocktrans %} }}} This way quite many countries will have possibility to translate this to correct form. -- Ticket URL: <https://code.djangoproject.com/ticket/11688#comment:7> 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 post to this group, send email to django-updates@googlegroups.com. To unsubscribe from this group, send email to django-updates+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-updates?hl=en.