summaryrefslogtreecommitdiff
path: root/docs/ref
diff options
context:
space:
mode:
authorMattias Loverot <mattias@stubin.se>2016-08-24 18:18:17 +0200
committerClaude Paroz <claude@2xlibre.net>2016-08-24 18:18:17 +0200
commit9aaeec337e217109208672d8fe47eeb49ca492b5 (patch)
tree4b815546bfd3b8a5844464c3cea9d397b792c4c2 /docs/ref
parentcf2cd4053fe3eed50ab2b7269ed72d25712c970a (diff)
Fixed #26866 -- Added format_lazy function
Added format_lazy function to django.utils.text module. Useful when dealing with relative complex lazy string concatenations (e.g. in urls.py when translating urls in regular expressions).
Diffstat (limited to 'docs/ref')
-rw-r--r--docs/ref/utils.txt20
1 files changed, 20 insertions, 0 deletions
diff --git a/docs/ref/utils.txt b/docs/ref/utils.txt
index e7b3b2a997..07fa53990e 100644
--- a/docs/ref/utils.txt
+++ b/docs/ref/utils.txt
@@ -868,6 +868,26 @@ appropriate entities.
.. module:: django.utils.text
:synopsis: Text manipulation.
+.. function:: format_lazy(format_string, *args, **kwargs)
+
+ .. versionadded:: 1.11
+
+ A version of :meth:`str.format` for when ``format_string``, ``args``,
+ and/or ``kwargs`` contain lazy objects. The first argument is the string to
+ be formatted. For example::
+
+ from django.utils.text import format_lazy
+ from django.utils.translation import pgettext_lazy
+
+ urlpatterns = [
+ url(format_lazy(r'{person}/(?P<pk>\d+)/$', person=pgettext_lazy('URL', 'person')),
+ PersonDetailView.as_view()),
+ ]
+
+ This example allows translators to translate part of the URL. If "person"
+ is translated to "persona", the regular expression will match
+ ``persona/(?P<pk>\d+)/$``, e.g. ``persona/5/``.
+
.. function:: slugify(allow_unicode=False)
Converts to ASCII if ``allow_unicode`` is ``False`` (default). Converts spaces to