diff --git a/docs/topics/i18n/translation.txt b/docs/topics/i18n/translation.txt
index cc4c24d..e49d768 100644
|
a
|
b
|
For example::
|
| 206 | 206 | In this example the number of objects is passed to the translation |
| 207 | 207 | languages as the ``count`` variable. |
| 208 | 208 | |
| 209 | | Lets see a slightly more complex usage example:: |
| | 209 | Note that pluralization is complicated and works differently in each language. |
| | 210 | Comparing ``count`` to 1 isn't always the correct rule. This code looks |
| | 211 | sophisticated, but will produce the wrong results for some languages:: |
| 210 | 212 | |
| 211 | 213 | from django.utils.translation import ungettext |
| 212 | 214 | from myapp.models import Report |
| … |
… |
Lets see a slightly more complex usage example::
|
| 218 | 220 | name = Report._meta.verbose_name_plural |
| 219 | 221 | |
| 220 | 222 | 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 |
| 224 | 226 | ) % { |
| 225 | 227 | 'count': count, |
| 226 | 228 | 'name': name |
| 227 | 229 | } |
| 228 | 230 | |
| 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. |
| | 231 | Don't try to implement your own singular-or-plural logic, it won't be correct. |
| 233 | 232 | |
| 234 | 233 | .. _pluralization-var-notes: |
| 235 | 234 | |
| 236 | 235 | .. note:: |
| 237 | 236 | |
| 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:: |
| 242 | 241 | |
| 243 | 242 | from django.utils.translation import ungettext |
| 244 | 243 | from myapp.models import Report |
| … |
… |
cardinality of the elements at play.
|
| 250 | 249 | 'plural_name': Report._meta.verbose_name_plural |
| 251 | 250 | } |
| 252 | 251 | 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 |
| 256 | 255 | ) % d |
| 257 | 256 | |
| 258 | 257 | You would get an error when running :djadmin:`django-admin.py |