diff --git a/docs/topics/i18n/translation.txt b/docs/topics/i18n/translation.txt
index cc4c24d..0202a88 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. |
| 232 | In a case like this, consider something like the following:: |
| 233 | |
| 234 | text = ungettext( |
| 235 | 'There is %(count)d %(name)s object available.', |
| 236 | 'There are %(count)d %(name)s objects available.', |
| 237 | count |
| 238 | ) % { |
| 239 | 'count': count, |
| 240 | 'name': Report._meta.verbose_name, |
| 241 | } |
233 | 242 | |
234 | 243 | .. _pluralization-var-notes: |
235 | 244 | |
236 | 245 | .. note:: |
237 | 246 | |
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:: |
| 247 | When using ``ungettext()``, make sure you use a single name for every |
| 248 | extrapolated variable included in the literal. In the examples above, note |
| 249 | how we used the ``name`` Python variable in both translation strings. This |
| 250 | example, besides being incorrect in some languages as noted above, would |
| 251 | fail:: |
242 | 252 | |
243 | | from django.utils.translation import ungettext |
244 | | from myapp.models import Report |
245 | | |
246 | | count = Report.objects.count() |
247 | | d = { |
248 | | 'count': count, |
| 253 | text = ungettext( |
| 254 | 'There is %(count)d %(name)s available.', |
| 255 | 'There are %(count)d %(plural_name)s available.', |
| 256 | count |
| 257 | ) % { |
| 258 | 'count': Report.objects.count(), |
249 | 259 | 'name': Report._meta.verbose_name, |
250 | 260 | 'plural_name': Report._meta.verbose_name_plural |
251 | 261 | } |
252 | | text = ungettext( |
253 | | 'There is %(count)d %(name)s available.', |
254 | | 'There are %(count)d %(plural_name)s available.', |
255 | | count |
256 | | ) % d |
257 | 262 | |
258 | 263 | You would get an error when running :djadmin:`django-admin.py |
259 | 264 | compilemessages <compilemessages>`:: |