Opened 2 years ago

Closed 5 months ago

#19300 closed Bug (worksforme)

capfirst filter breaks translation context in template

Reported by: dyve 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 (5)

comment:1 Changed 2 years ago by aaugustin

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to worksforme
  • Status changed from new to closed

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 2 years ago by dyve

Will test again to see if it is fixed.

comment:3 Changed 2 years ago by dyve

Confirmed, it works

comment:4 Changed 5 months ago by liminspace

  • Resolution worksforme deleted
  • Status changed from closed to new
  • Version changed from 1.4 to 1.7

The problem is actual again :(

comment:5 Changed 5 months ago by tricoder42

  • Resolution set to worksforme
  • Status changed from new to closed

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?

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