Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#6325 closed (invalid)

fix test case for _() in templates, improve documentation

Reported by: Antti Kaihola Owned by: nobody
Component: Internationalization Version: master
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


The _() construct available for templates doesn't work as explained in the documentation, and there are no actual unit tests for it either.

Here is a test script to illustrate the problem:

from django.conf import settings

from django.template import Template, Context

template = Template(
    u'{% load i18n %}'
    u'{% trans "Yes" %} '
    u'{{ true|yesno:_("Yes,No") }} '
    u'{{ false|yesno:_("Yes,No") }}')

context = Context({'true': True, 'false': False})
print template.render(context)

This should print out the Finnish translation of "Yes" twice and "No" once:

Kyllä Kyllä Ei

but only {% trans %} works correctly, and the script in fact prints

Kyllä Yes No

There's [source:django/trunk/tests/regressiontests/templates/ a test case] which probably is meant to test this, but fails to do so:

'i18n10': ('{{ bool|yesno:_("ja,nein") }}', {'bool': True}, 'ja'),

I assume this is what was intended:

'i18n10': ('{{ bool|yesno:_("Yes,No") }}', {'bool': True, 'LANGUAGE_CODE': 'de'}, 'Ja'),

and it currently fails:

Template test (TEMPLATE_STRING_IF_INVALID='INVALID'): i18n10 -- FAILED. Expected 'Ja', got u'Yes'

Attachments (1)

6325_tests.diff (776 bytes) - added by Antti Kaihola 11 years ago.
fix for the test case (same as in bug description)

Download all attachments as: .zip

Change History (4)

Changed 11 years ago by Antti Kaihola

Attachment: 6325_tests.diff added

fix for the test case (same as in bug description)

comment:1 Changed 11 years ago by Antti Kaihola

Summary: _() broken in templates, tests are invalidfix test case for _() in templates, improve documentation

Oops, I misunderstood the documentation when writing the original bug report ("_() broken in templates"). But there actually is still a problem in unit tests and room for improvement in the documentation.

Maybe it should be clarified in the documentation for _() in templates that |yesno:_("yes,no") actually looks for the string "yes,no" in the translation files, not for "yes" and "no" separately.

And it would be better to use an actual existing translation string like "yes,no,maybe" instead of "yes,no" in the example.

Also, [source:django/trunk/tests/regressiontests/templates/ the test case for _() in templates] is invalid:

'i18n10': ('{{ bool|yesno:_("ja,nein") }}', {'bool': True}, 'ja'),

This should be better, and it does pass:

'i18n10': ('{{ bool|yesno:_("yes,no,maybe") }}', {'bool': True, 'LANGUAGE_CODE': 'de'}, 'Ja'),

comment:2 Changed 11 years ago by Antti Kaihola

Resolution: invalid
Status: newclosed

comment:3 Changed 11 years ago by Antti Kaihola

Opened a new ticket for the unit test and documentation improvement suggestions.

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