#26866: Lazy variant of string format
--------------------------------------+--------------------
     Reporter:  lovmat                |      Owner:  nobody
         Type:  New feature           |     Status:  new
    Component:  Internationalization  |    Version:  master
     Severity:  Normal                |   Keywords:
 Triage Stage:  Unreviewed            |  Has patch:  0
Easy pickings:  0                     |      UI/UX:  0
--------------------------------------+--------------------
 I'd like to contribute with creating a lazy variant of str format method:
 https://docs.python.org/3/library/stdtypes.html#str.format

 Very similar to the string_concat function:
 
https://github.com/django/django/blob/master/django/utils/translation/__init__.py#L221-L227

 This allows more advanced string formatting with lazy strings. My
 particular use case is urls.py where I don't want translators to get a
 chance to translate regular expressions - only the actual url piece. I
 ended up with:

 {{{
 #!div style="font-size: 80%"
 Proposal:
   {{{#!python
   from django.utils.translation import pgettext_lazy, string_format

   t = {
       'mypages': pgettext_lazy('Url', 'mypages'),
       'objects': pgettext_lazy('Url', 'objects')
   }

   urlpatterns = [
       url(string_format('^{mypages}/{objects}/$', **t),
 views.ObjectView.as_view(), name='objects')
   ]
   }}}
 }}}

 {{{
 #!div style="font-size: 80%"
 With string_concat:
   {{{#!python
       url(string_concat('^', t['mypages'], '/', t['objects'], '/$'),
 views.ObjectView.as_view(), name='objects')
   }}}
 }}}

 If you accept the proposal I'll make a pull request. Thanks.

--
Ticket URL: <https://code.djangoproject.com/ticket/26866>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/049.51c26fe1ea0c3431cabbc469ba9e4456%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to