mirror of https://github.com/django/django.git
Fixed #19132 -- Added example for creating custom lazy function
Thanks flagzeta@yahoo.it for the report and Luke Plant for his expert assistance.
This commit is contained in:
parent
31dcaf49a0
commit
0775ab2955
|
@ -427,6 +427,24 @@ In this case, the lazy translations in ``result`` will only be converted to
|
||||||
strings when ``result`` itself is used in a string (usually at template
|
strings when ``result`` itself is used in a string (usually at template
|
||||||
rendering time).
|
rendering time).
|
||||||
|
|
||||||
|
Other uses of lazy in delayed translations
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
For any other case where you would like to delay the translation, but have to
|
||||||
|
pass the translatable string as argument to another function, you can wrap
|
||||||
|
this function inside a lazy call yourself. For example::
|
||||||
|
|
||||||
|
from django.utils import six # Python 3 compatibility
|
||||||
|
from django.utils.functional import lazy
|
||||||
|
from django.utils.safestring import mark_safe
|
||||||
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
|
mark_safe_lazy = lazy(mark_safe, six.text_type)
|
||||||
|
|
||||||
|
And then later::
|
||||||
|
|
||||||
|
lazy_string = mark_safe_lazy(_("<p>My <strong>string!</strong></p>"))
|
||||||
|
|
||||||
Localized names of languages
|
Localized names of languages
|
||||||
----------------------------
|
----------------------------
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue