Opened 6 years ago

Closed 6 years ago

Last modified 5 years ago

#13568 closed (fixed)

KeyError raised in template rendering when the number of placeholders differs between singular and plural

Reported by: deltoide Owned by: deltoide
Component: Internationalization Version: master
Severity: Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

Here is a simple example to reproduce the bug:

template file: index.html

{% load i18n %}

{% blocktrans with myextra_field as extra_field and myamount as amount count myyears as years %}
That will cost $ {{ amount }} per year. {{ extra_field }}
{% plural %}
That will cost $ {{ amount }} per {{ years }} years.
{% endblocktrans %}

views.py:

from django.http import HttpResponse
from django.template import Context, loader
from django.http import HttpResponse
def index(request):
    t = loader.get_template('index.html')
    c = Context({
          'myamount' : 10,
          'myyears' : 1,
          'myextra_field' : 2,
    })
    return HttpResponse(t.render(c))

Attachments (2)

i18n_13568.diff (1.8 KB) - added by deltoide 6 years ago.
Fix + regression test
i18n_13568.2.diff (1.8 KB) - added by deltoide 6 years ago.
Fix + regression test (with link to this bug 13568)

Download all attachments as: .zip

Change History (8)

comment:1 Changed 6 years ago by deltoide

Needs documentation: unset
Needs tests: unset
Owner: changed from nobody to deltoide
Patch needs improvement: unset

Changed 6 years ago by deltoide

Attachment: i18n_13568.diff added

Fix + regression test

comment:2 Changed 6 years ago by deltoide

Has patch: set

Changed 6 years ago by deltoide

Attachment: i18n_13568.2.diff added

Fix + regression test (with link to this bug 13568)

comment:3 Changed 6 years ago by Russell Keith-Magee

milestone: 1.3
Triage Stage: UnreviewedReady for checkin

comment:4 Changed 6 years ago by Jannis Leidel

Resolution: fixed
Status: newclosed

(In [13967]) Fixed #13568 -- Fixed the blocktrans tag to not raise a KeyError if the number of variables in the singular and the plural block differ. Thanks, deloide.

comment:5 Changed 6 years ago by Jannis Leidel

(In [13973]) [1.2.X] Fixed #13568 -- Fixed the blocktrans tag to not raise a KeyError if the number of variables in the singular and the plural block differ. Thanks, deloide.

Backport from trunk (r13967).

comment:6 Changed 5 years ago by Jacob

milestone: 1.3

Milestone 1.3 deleted

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