From 9aaeec337e217109208672d8fe47eeb49ca492b5 Mon Sep 17 00:00:00 2001 From: Mattias Loverot Date: Wed, 24 Aug 2016 18:18:17 +0200 Subject: 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). --- docs/ref/utils.txt | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'docs/ref') 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\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\d+)/$``, e.g. ``persona/5/``. + .. function:: slugify(allow_unicode=False) Converts to ASCII if ``allow_unicode`` is ``False`` (default). Converts spaces to -- cgit v1.3