{% 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
--
Ticket URL: <https://code.djangoproject.com/ticket/19300>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* status: new => closed
* needs_better_patch: => 0
* resolution: => worksforme
* needs_tests: => 0
* needs_docs: => 0
Comment:
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
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/19300#comment:1>
Comment (by dyve):
Will test again to see if it is fixed.
--
Ticket URL: <https://code.djangoproject.com/ticket/19300#comment:2>
Comment (by dyve):
Confirmed, it works
--
Ticket URL: <https://code.djangoproject.com/ticket/19300#comment:3>
* status: closed => new
* version: 1.4 => 1.7
* resolution: worksforme =>
Comment:
The problem is actual again :(
--
Ticket URL: <https://code.djangoproject.com/ticket/19300#comment:4>
* status: new => closed
* resolution: => worksforme
Comment:
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" %}
}}}
{{{#!python
# 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?
--
Ticket URL: <https://code.djangoproject.com/ticket/19300#comment:5>
* status: closed => new
* resolution: worksforme =>
Comment:
Same problem with Django 1.8.8.
--
Ticket URL: <https://code.djangoproject.com/ticket/19300#comment:6>
* status: new => closed
* resolution: => needsinfo
Comment:
Several people have tried and failed to reproduce the issue, as shown in
the comments above. Can you provide reproduction instructions? Thanks.
--
Ticket URL: <https://code.djangoproject.com/ticket/19300#comment:7>
* 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>
Comment (by Dylan Verheul):
Thanks for the explanation, explains everything. Good to know it's fixed.
I can confirm we haven't seen this bug since moving away from 1.8.
--
Ticket URL: <https://code.djangoproject.com/ticket/19300#comment:9>