Ticket #21650: 21650.diff

File 21650.diff, 2.6 KB (added by Tim Graham, 11 years ago)
  • docs/topics/i18n/translation.txt

    diff --git a/docs/topics/i18n/translation.txt b/docs/topics/i18n/translation.txt
    index cc4c24d..e49d768 100644
    a b For example::  
    206206In this example the number of objects is passed to the translation
    207207languages as the ``count`` variable.
    208208
    209 Lets see a slightly more complex usage example::
     209Note that pluralization is complicated and works differently in each language.
     210Comparing ``count`` to 1 isn't always the correct rule. This code looks
     211sophisticated, but will produce the wrong results for some languages::
    210212
    211213    from django.utils.translation import ungettext
    212214    from myapp.models import Report
    Lets see a slightly more complex usage example::  
    218220        name = Report._meta.verbose_name_plural
    219221
    220222    text = ungettext(
    221             'There is %(count)d %(name)s available.',
    222             'There are %(count)d %(name)s available.',
    223             count
     223        'There is %(count)d %(name)s available.',
     224        'There are %(count)d %(name)s available.',
     225        count
    224226    ) % {
    225227        'count': count,
    226228        'name': name
    227229    }
    228230
    229 Here we reuse localizable, hopefully already translated literals (contained in
    230 the ``verbose_name`` and ``verbose_name_plural`` model ``Meta`` options) for
    231 other parts of the sentence so all of it is consistently based on the
    232 cardinality of the elements at play.
     231Don't try to implement your own singular-or-plural logic, it won't be correct.
    233232
    234233.. _pluralization-var-notes:
    235234
    236235.. note::
    237236
    238     When using this technique, make sure you use a single name for every
    239     extrapolated variable included in the literal. In the example above note how
    240     we used the ``name`` Python variable in both translation strings. This
    241     example would fail::
     237    When using ``ungettext()``, make sure you use a single name for every
     238    extrapolated variable included in the literal. In the (albeit flawed)
     239    example above, note how we used the ``name`` Python variable in both
     240    translation strings. This example would fail::
    242241
    243242        from django.utils.translation import ungettext
    244243        from myapp.models import Report
    cardinality of the elements at play.  
    250249            'plural_name': Report._meta.verbose_name_plural
    251250        }
    252251        text = ungettext(
    253                 'There is %(count)d %(name)s available.',
    254                 'There are %(count)d %(plural_name)s available.',
    255                 count
     252            'There is %(count)d %(name)s available.',
     253            'There are %(count)d %(plural_name)s available.',
     254            count
    256255        ) % d
    257256
    258257    You would get an error when running :djadmin:`django-admin.py
Back to Top