Code

Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#6325 closed (invalid)

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

Reported by: akaihola 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: UI/UX:

Description

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
settings.configure(LANGUAGE_CODE='fi')

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/tests.py#6996#L739 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 akaihola 6 years ago.
fix for the test case (same as in bug description)

Download all attachments as: .zip

Change History (4)

Changed 6 years ago by akaihola

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

comment:1 Changed 6 years ago by akaihola

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Summary changed from _() broken in templates, tests are invalid to fix 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/tests.py#6996#L739 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 6 years ago by akaihola

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

comment:3 Changed 6 years ago by akaihola

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

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.