﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
26866	Lazy variant of string format	Mattias Loverot	nobody	"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."	New feature	closed	Internationalization	dev	Normal	fixed		Claude Paroz	Ready for checkin	1	0	0	0	0	0
