Opened 5 years ago

Closed 5 years ago

Last modified 4 years ago

#13568 closed (fixed)

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

Reported by: deloide Owned by: deloide
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 deloide 5 years ago.
Fix + regression test
i18n_13568.2.diff (1.8 KB) - added by deloide 5 years ago.
Fix + regression test (with link to this bug 13568)

Download all attachments as: .zip

Change History (8)

comment:1 Changed 5 years ago by deloide

  • Needs documentation unset
  • Needs tests unset
  • Owner changed from nobody to deloide
  • Patch needs improvement unset

Changed 5 years ago by deloide

Fix + regression test

comment:2 Changed 5 years ago by deloide

  • Has patch set

Changed 5 years ago by deloide

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

comment:3 Changed 5 years ago by russellm

  • milestone set to 1.3
  • Triage Stage changed from Unreviewed to Ready for checkin

comment:4 Changed 5 years ago by jezdez

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

(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 5 years ago by jezdez

(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 4 years ago by jacob

  • milestone 1.3 deleted

Milestone 1.3 deleted

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