#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)
Change History (10)
comment:1 by , 14 years ago
Resolution: | → worksforme |
---|---|
Status: | new → closed |
by , 14 years ago
Attachment: | test14126.patch added |
---|
comment:2 by , 14 years ago
Resolution: | worksforme |
---|---|
Status: | closed → reopened |
Triage Stage: | Unreviewed → Design 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 , 14 years ago
Attachment: | django-1-result.patch added |
---|
comment:3 by , 14 years ago
Owner: | changed from | to
---|---|
Status: | reopened → new |
comment:4 by , 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 , 14 years ago
Attachment: | blocktrans.diff added |
---|
comment:5 by , 14 years ago
@ramiro, you was right, translation is correct. Please, look at the new patch which fixes blocktrans' code.
comment:6 by , 14 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Can't reproduce with attached test.