Opened 14 years ago

Closed 14 years ago

Last modified 14 years ago

#14126 closed (fixed)

blocktrans count is parsing incorrectly

Reported by: Mark Jones Owned by: Ramiro Morales
Component: Translations Version: 1.2
Severity: Keywords: blocktrans plural
Cc: Triage Stage: Design decision needed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Context looks like: {'docs_needed': 2, ... (from the stack trace provided)

    {% blocktrans count docs_needed as counter %} 

Generates this error: Caught KeyError while rendering: u'docs_needed'

    {% blocktrans count docs_needed|default:2 as counter %} 

Generates this error: Caught KeyError while rendering: u'docs_needed'

    {% blocktrans count docs_needed|length as counter %}

Does not give a KeyError, but produces the wrong result since the length of docs_needed is 1 since it is scalar?

The template contains:

			{% blocktrans count docs_needed|length as counter %}
				<h3>Waiting on the following document:</h3>
			{% plural %}
				<h3>Waiting on the following {{ counter }} documents:</h3>
			{% endblocktrans %}

and the output produced looks like:

    <h3>Waiting on the following  documents:</h3>

The documentation @ http://docs.djangoproject.com/en/dev/topics/i18n/internationalization/#blocktrans-template-tag makes it look like a scalar is needed after the word key word count because it uses list|length as an example, which appears to be a filter creating a scalar value.

I'm using Django 1.2.1 (not a version you can pick below)

Attachments (3)

test14126.patch (1.3 KB ) - added by Matthias Kestenholz 14 years ago.
django-1-result.patch (835 bytes ) - added by Alexander Artemenko 14 years ago.
blocktrans.diff (1.7 KB ) - added by Alexander Artemenko 14 years ago.

Download all attachments as: .zip

Change History (10)

comment:1 by Matthias Kestenholz, 14 years ago

Resolution: worksforme
Status: newclosed

Can't reproduce with attached test.

by Matthias Kestenholz, 14 years ago

Attachment: test14126.patch added

comment:2 by Alexander Artemenko, 14 years ago

Resolution: worksforme
Status: closedreopened
Triage Stage: UnreviewedDesign decision needed

Actually it is not blocktrans issue, but translation file issue.

For example this error takes place when you have LANGUAGE_CODE = 'ru' in your settings.py.

Reason — wrong django.po for this particular language. It's singular form requires keyword argument:

#: contrib/admin/templates/admin/search_form.html:10
#, python-format
msgid "1 result"
msgid_plural "%(counter)s results"
msgstr[0] "%(counter)s результат"
msgstr[1] "%(counter)s результата"
msgstr[2] "%(counter)s результатов"

It should be fixed in this way:

#: contrib/admin/templates/admin/search_form.html:10
#, python-format
msgid "1 result"
msgid_plural "%(counter)s results"
msgstr[0] "1 результат"
msgstr[1] "%(counter)s результата"
msgstr[2] "%(counter)s результатов"

by Alexander Artemenko, 14 years ago

Attachment: django-1-result.patch added

comment:3 by Ramiro Morales, 14 years ago

Owner: changed from nobody to Ramiro Morales
Status: reopenednew

comment:4 by Ramiro Morales, 14 years ago

@mark0978:

The case you report (no additional variables bound in the blocktrans tag, only the counter var, and the counter variable being used in the plural literal but not in the singular one) is being tested in the Django 1.2.1 (and the current trunk, unchanged since then) suite (see i18n07 and i18n08 tests): http://code.djangoproject.com/browser/django/tags/releases/1.2.1/tests/regressiontests/templates/tests.py#L1069 -- so there must be some additional detail(s) to your setup (like the language you are translating to and the relevant fragment of the .po file you are using) so please post them if you read this.

@svetlyak40wt:

That fragment of the Russian translation is correct: the 0th plural form isn't being used exclusively for the counter=1 case. According to the Plural forms formula for that language (located at the top of the same file), that form is also used for, e.g., when count is 21, 31,...

by Alexander Artemenko, 14 years ago

Attachment: blocktrans.diff added

comment:5 by Alexander Artemenko, 14 years ago

@ramiro, you was right, translation is correct. Please, look at the new patch which fixes blocktrans' code.

comment:6 by Jannis Leidel, 14 years ago

Resolution: fixed
Status: newclosed

(In [14239]) Fixed #14126 -- Fixed an issue with changes to the blocktrans tag introduced in r13967 related to multiple plural forms. Thanks, mark0978, svetlyak40wt and Ramiro.

comment:7 by Jannis Leidel, 14 years ago

(In [14240]) [1.2.X] Fixed #14126 -- Fixed an issue with changes to the blocktrans tag introduced in r13973 related to multiple plural forms. Thanks, mark0978, svetlyak40wt and Ramiro.

Backport from trunk (r14239).

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