Opened 3 years ago

Closed 2 years ago

#18114 closed Bug (duplicate)

makemessages does not care about context in trans templatetag

Reported by: tomaz.stucin@… Owned by: nobody
Component: Core (Management commands) Version: 1.4
Severity: Normal Keywords: trans context pgettext makemessages i18n
Cc: AkosLadanyi Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by ramiro)

We are working with translations and we have done the following

  • we have 2 templates: template1.html and template2.html
  • in template1 we have the following:
    {% trans 'contact' as trans_contact %}
    
  • in template2 we have the following:
    {% trans 'contact' context 'suggesttive' as trans_contact %}
    
  • when we makemessages -a we get the following in the django.po file:
    #: web/templates/web/template1.html:35
    #: web/templates/web/template2.html:21
    msgid "contact"
    msgstr ""
    
  • what we expect instead (in django.po) is actually:
    #: web/templates/web/template1.html:35
    msgid "contact"
    msgstr ""
    #: web/templates/web/template2.html:21
    msgctxt "suggesttive"
    msgid "contact"
    msgstr ""
    

So it seems that the "django-admin.py makemessages -a" does not take into account context in the trans templatetag (but it does process both trans tag as can be seen in the comment)

If we write (anywhere in the code) the following:

from django.utils.translation import pgettext
test = pgettext('suggesttive', 'contact')

then the django.po content is as expected and if we translate the strings (in django.po) and then render the template, the context is taken into account and the translation on the webpage (produced from the template) is as it should be, so the trans templatetag works as expected, just the makemessages does not.

If this is a "feature" I apologize in advance.

Attachments (2)

18114.trans-context.py (2.0 KB) - added by julien 3 years ago.
18114.trans-context.diff (2.0 KB) - added by julien 3 years ago.
Same patch but with .diff extension

Download all attachments as: .zip

Change History (12)

comment:1 Changed 3 years ago by tomaz.stucin@…

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

sorry, there is a typo in my report: in my code it is not:

{trans ...

but it is:
{% trasn ...
}}}

so this is definitely not the problem.

comment:2 Changed 3 years ago by julien

Thanks for the report, however I cannot reproduce your issue (see the attached test case). Are you able to provide a test case for Django that highlights the problem?

Changed 3 years ago by julien

Changed 3 years ago by julien

Same patch but with .diff extension

comment:3 Changed 3 years ago by AkosLadanyi

  • Cc AkosLadanyi added

comment:4 Changed 3 years ago by jezdez

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

comment:5 follow-up: Changed 2 years ago by anonymous

We just hit the same problem. In our case it seems to be related to single quote versus double quote. If we set the context keyword in single quotes makemessages ignores the context and sets the translation to have no context. If we change to double quote it then considers the context keyword.

Example:

Works:
{% trans 'Active' context "plural" %}

Doesn't work:
{% trans 'Active' context 'plural' %}

comment:6 Changed 2 years ago by ramiro

  • Component changed from Translations to Core (Management commands)
  • Description modified (diff)
  • Keywords makemessages i18n added

comment:7 in reply to: ↑ 5 Changed 2 years ago by ramiro

  • Resolution needsinfo deleted
  • Status changed from closed to new

Replying to anonymous:

We just hit the same problem.

What version of Django are you using?

Reopening so we can track this now that there is one user providing additional information.

comment:8 Changed 2 years ago by kozz

Django 1.4(.0)

comment:9 Changed 2 years ago by ramiro

  • Description modified (diff)

comment:10 Changed 2 years ago by ramiro

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

Duplicate of #18881. Install the latest 1.4.x bug-fix release (currently 1.4.3) to get the fix.

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