diff --git a/docs/ref/templates/builtins.txt b/docs/ref/templates/builtins.txt
a
|
b
|
|
2061 | 2061 | |
2062 | 2062 | A collection of template tags that can be useful while designing a website, |
2063 | 2063 | such as a generator of Lorem Ipsum text. See :ref:`ref-contrib-webdesign`. |
| 2064 | |
| 2065 | i18n |
| 2066 | ~~~~ |
| 2067 | |
| 2068 | Provides a couple of templatetags that allow specifying translatable text in |
| 2069 | Django templates. It is slightly different from the libraries described |
| 2070 | above because you don't need to add any application to the ``INSTALLED_APPS`` |
| 2071 | setting but rather set :setting:`USE_I18N` to True, then loading it with |
| 2072 | ``{% load i18n %}``. See :ref:`specifying-translation-strings-in-template-code`. |
diff --git a/docs/topics/i18n/internationalization.txt b/docs/topics/i18n/internationalization.txt
a
|
b
|
|
325 | 325 | input is a proper string, then add support for lazy translation objects at the |
326 | 326 | end. |
327 | 327 | |
| 328 | .. _specifying-translation-strings-in-template-code: |
| 329 | |
328 | 330 | Specifying translation strings: In template code |
329 | 331 | ================================================ |
330 | 332 | |
… |
… |
|
334 | 336 | tags and a slightly different syntax than in Python code. To give your template |
335 | 337 | access to these tags, put ``{% load i18n %}`` toward the top of your template. |
336 | 338 | |
| 339 | ``trans`` template tag |
| 340 | ---------------------- |
| 341 | |
337 | 342 | The ``{% trans %}`` template tag translates either a constant string |
338 | 343 | (enclosed in single or double quotes) or variable content:: |
339 | 344 | |
… |
… |
|
348 | 353 | |
349 | 354 | Internally, inline translations use an ``ugettext`` call. |
350 | 355 | |
| 356 | In the translation of a template var case (``myvar`` above), at run-time the tag |
| 357 | first resolves such variable to a string and then looks up that string in the |
| 358 | message catalogs. |
| 359 | |
351 | 360 | It's not possible to mix a template variable inside a string within ``{% trans |
352 | 361 | %}``. If your translations require strings with variables (placeholders), use |
353 | | ``{% blocktrans %}``:: |
| 362 | ``{% blocktrans %}`` instead. |
| 363 | |
| 364 | ``blocktrans`` template tag |
| 365 | --------------------------- |
| 366 | |
| 367 | Contrarily to the ``trans`` tag, ``blocktrans`` allows to mark as translatable |
| 368 | complex sentences with mixed literal and variable content at template |
| 369 | creation-time by making use of placeholders:: |
354 | 370 | |
355 | 371 | {% blocktrans %}This string will have {{ value }} inside.{% endblocktrans %} |
356 | 372 | |
357 | | To translate a template expression -- say, using template filters -- you need |
358 | | to bind the expression to a local variable for use within the translation |
359 | | block:: |
| 373 | To translate a template expression -- say, accessing object attributes or using |
| 374 | template filters -- you need to bind the expression to a local variable for use |
| 375 | within the translation block. Examples:: |
| 376 | |
| 377 | {% blocktrans with article.price as amount %} |
| 378 | That will cost $ {{ amount }}. |
| 379 | {% endblocktrans %} |
360 | 380 | |
361 | 381 | {% blocktrans with value|filter as myvar %} |
362 | 382 | This will have {{ myvar }} inside. |
… |
… |
|
369 | 389 | This is {{ book_t }} by {{ author_t }} |
370 | 390 | {% endblocktrans %} |
371 | 391 | |
372 | | To pluralize, specify both the singular and plural forms with the |
373 | | ``{% plural %}`` tag, which appears within ``{% blocktrans %}`` and |
374 | | ``{% endblocktrans %}``. Example:: |
| 392 | This tag is also in charge of handling another functionality: Pluralization. To |
| 393 | make use of it you should: |
| 394 | |
| 395 | * Designate and bind a counter value by using ``count``, such value will be |
| 396 | the one used to select the right plural form. |
| 397 | |
| 398 | * Specify both the singular and plural forms separating them with the |
| 399 | ``{% plural %}`` tag, which appears within ``{% blocktrans %}`` and |
| 400 | ``{% endblocktrans %}``. |
| 401 | |
| 402 | An example:: |
375 | 403 | |
376 | 404 | {% blocktrans count list|length as counter %} |
377 | 405 | There is only one {{ name }} object. |
… |
… |
|
379 | 407 | There are {{ counter }} {{ name }} objects. |
380 | 408 | {% endblocktrans %} |
381 | 409 | |
382 | | When you use the pluralization feature and bind additional values to local |
383 | | variables apart from the counter value that selects the translated literal to be |
384 | | used, have in mind that the ``blocktrans`` construct is internally converted |
385 | | to an ``ungettext`` call. This means the same :ref:`notes regarding ungettext |
386 | | variables <pluralization-var-notes>` apply. |
| 410 | A more complex example:: |
| 411 | |
| 412 | {% blocktrans with article.price as amount count i.length as years %} |
| 413 | That will cost $ {{ amount }} per year. |
| 414 | {% plural %} |
| 415 | That will cost $ {{ amount }} per {{ years }} years. |
| 416 | {% endblocktrans %} |
| 417 | |
| 418 | When you both use the pluralization feature and bind values to local variables |
| 419 | in addition to the counter value, have in mind that the ``blocktrans`` construct |
| 420 | is internally converted to an ``ungettext`` call. This means the same |
| 421 | :ref:`notes regarding ungettext variables <pluralization-var-notes>` apply. |
387 | 422 | |
388 | 423 | .. _template-translation-vars: |
389 | 424 | |
| 425 | Other tags |
| 426 | ---------- |
| 427 | |
390 | 428 | Each ``RequestContext`` has access to three translation-specific variables: |
391 | 429 | |
392 | 430 | * ``LANGUAGES`` is a list of tuples in which the first element is the |
… |
… |
|
400 | 438 | right-to-left language, e.g.: Hebrew, Arabic. If False it's a |
401 | 439 | left-to-right language, e.g.: English, French, German etc. |
402 | 440 | |
403 | | |
404 | 441 | If you don't use the ``RequestContext`` extension, you can get those values with |
405 | 442 | three tags:: |
406 | 443 | |