#19300: capfirst filter breaks translation context in template
-------------------------------------+-------------------------------------
     Reporter:  Dylan Verheul        |                    Owner:  nobody
         Type:  Bug                  |                   Status:  closed
    Component:  Template system      |                  Version:  1.7
     Severity:  Normal               |               Resolution:  fixed
     Keywords:  trans context        |             Triage Stage:
  capfirst                           |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by Przemysław "Pirax" Czumaj):

 * resolution:  needsinfo => fixed


Comment:

 OK, I'll leave a reproduction example below if anyone will be interested,
 but after some more digging I found out what the issue was.

 Within ''django/django/utils/translation/trans_real.py'' file there was an
 **inline_re** regex and this regex was badly constructed - up to Django
 1.8.18. There was no "filters" block between translated string and a
 "context" keyword, so construction
 {{{
 {% trans 'string'|capfirst context 'context' %}
 }}}
 couldn't be recognised properly. This issue was fixed in Django 1.9.

 So that's it. If you are still using Django 1.8 and need a fix for it use
 {{{
 {% filter capfirst %}{% trans 'string' context 'context' %}{% endfilter %}
 }}}
 construction instead or update your Django version.


 ----

 I can provide additional information to this issue as I'm fighting with it
 right now.

 Let's assume I have a template like this:
 {{{
 {% trans 'test_clean' %}
 {% trans 'test_capfirst'|capfirst %}
 {% trans 'test_context' context 'test_context' %}
 {% trans 'test_context'|capfirst context 'test_context' %}
 {% filter capfirst %}{% trans 'test_filter_context' context 'test_context'
 %}{% endfilter %}
 }}}

 Now let's run ''makemessages''...

 For:
 {{{
 {% trans 'test_clean' %}
 }}}
 I got:
 {{{
 msgid "test_clean"
 msgstr ""
 }}}

 Result: OK!

 For:
 {{{
 {% trans 'test_capfirst'|capfirst %}
 }}}
 I got:
 {{{
 msgid "test_capfirst"
 msgstr ""
 }}}

 Result: OK!

 For:
 {{{
 {% trans 'test_context' context 'test_context' %}
 }}}
 I got:
 {{{
 msgctxt "test_context"
 msgid "test_context"
 msgstr ""
 }}}

 Result: OK! Context is set as it should be.

 For:
 {{{
 {% trans 'test_context'|capfirst context 'test_context' %}
 }}}
 I got:
 {{{
 msgid "test_context_capfirst"
 msgstr ""
 }}}

 Comment: NOT OK! "msgctxt" key is missing, therefore Context is not set.

 For:
 {{{
 {% filter capfirst %}{% trans 'test_filter_context' context 'test_context'
 %}{% endfilter %}
 }}}
 I got:
 {{{
 msgctxt "test_context"
 msgid "test_filter_context"
 msgstr ""
 }}}

 Comment: OK! Context is set as it should be.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/19300#comment:8>
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 django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/062.8572ba460f221941dfd18d7f93dd4913%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to