Opened 4 years ago

Closed 9 months ago

#19300 closed Bug (needsinfo)

capfirst filter breaks translation context in template

Reported by: Dylan Verheul Owned by: nobody
Component: Template system Version: 1.7
Severity: Normal Keywords: trans context capfirst
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Using the cap first filter breaks any context used in translation using the trans template tag.

{% trans "species" context "singular" %}
# works as expected, results in translation of 'species' with context 'singular'

{% trans "species"|capfirst %}
# works as expected, results in translation of 'species' without context, capfirst applied

{% trans "species"|capfirst context "singular" %}
# BROKEN, results in translation of 'species' without context, capfirst applied

Change History (7)

comment:1 Changed 4 years ago by Aymeric Augustin

Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset
Resolution: worksforme
Status: newclosed

I can't reproduce the issue on master.

With this template and the appropriate French translations:

{% trans "species" %}
# works as expected, results in translation of 'species'

{% trans "species" context "singular" %}
# works as expected, results in translation of 'species' with context 'singular'

{% trans "species"|capfirst %}
# works as expected, results in translation of 'species' without context, capfirst applied

{% trans "species"|capfirst context "singular" %}
# works as expected, results in translation of 'species' with context 'singular', capfirst applied

I get this output:

espèces # works as expected, results in translation of 'species'

espèce # works as expected, results in translation of 'species' with context 'singular'

Espèces # works as expected, results in translation of 'species' without context, capfirst applied

Espèce # works as expected, results in translation of 'species' with context 'singular', capfirst applied

comment:2 Changed 4 years ago by Dylan Verheul

Will test again to see if it is fixed.

comment:3 Changed 4 years ago by Dylan Verheul

Confirmed, it works

comment:4 Changed 23 months ago by None

Resolution: worksforme
Status: closednew
Version: 1.41.7

The problem is actual again :(

comment:5 Changed 22 months ago by Tomáš Ehrlich

Resolution: worksforme
Status: newclosed

Hi,
I tried to reproduce this problem, but it works for me:

# django.po
#: templates/test.html:3 templates/test.html.py:5 templates/test.html.py:6
msgid "species"
msgstr "espèces"

#: templates/test.html:4
msgctxt "singular"
msgid "species"
msgstr "espèce"
# test.html
{% load i18n %}

{% trans "species" %}
{% trans "species" context "singular" %}
{% trans "species"|capfirst %}
{% trans "species"|capfirst context "singular" %}
# tests.py
from django.template import Context
from django.template.loader import get_template

tmpl = get_template('test.html')
print(tmpl.render(Context({})))
# output
espèces
espèce
Espèces
Espèce

The message catalogue has wrong references for plural "species", but references are just informational. It doesn't affect the result.

If it still doesn't work for you (tested against 1.7.1 and master), could you please provide more info to reproduce this bug?

comment:6 Changed 9 months ago by Pascal Polleunus

Resolution: worksforme
Status: closednew

Same problem with Django 1.8.8.

comment:7 Changed 9 months ago by Aymeric Augustin

Resolution: needsinfo
Status: newclosed

Several people have tried and failed to reproduce the issue, as shown in the comments above. Can you provide reproduction instructions? Thanks.

Note: See TracTickets for help on using tickets.
Back to Top