[Django] #35698: Pluralised blocktranslate doesn't translate

8 views
Skip to first unread message

Django

unread,
Aug 21, 2024, 5:18:50 AM8/21/24
to django-...@googlegroups.com
#35698: Pluralised blocktranslate doesn't translate
-----------------------+------------------------------------------------
Reporter: nootr | Type: Uncategorized
Status: new | Component: Internationalization
Version: 4.2 | Severity: Normal
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------+------------------------------------------------
Translating with `{% blocktranslate %}` or `{% blocktrans %}` does
translate. However, when I add `count counter=1`, the correct sentence is
used, but not translated.

**How to reproduce**

I'm able to reproduce the issue by setting up a minimal Django 4.2.15
project on MacOS:

{{{
python3 -m venv venv
source venv/bin/activate
pip install Django==4.2.15

django-admin startproject blocktranstest
cd blocktranstest/
./manage.py startapp home
mkdir -p home/templates/home
}}}

Add the following settings to ''blocktranstest/settings.py'':

{{{
from django.utils.translation import gettext_lazy as _

LANGUAGE_CODE = "nl-NL"
LANGUAGES = [("nl", _("Nederlands"))]
MIDDLEWARE = [
"django.middleware.security.SecurityMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.locale.LocaleMiddleware", # Added
"django.middleware.common.CommonMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
]
INSTALLED_APPS += ["home"]
}}}

home/templates/home/index.html:

{{{
{% load i18n %}
<p style="color: green">{% trans "Please correct the error below." %}</p>
<p style="color: green">{% trans "Please correct the errors below." %}</p>
<p style="color: green">{% blocktranslate %}Please correct the error
below.{% endblocktranslate %}</p>
<p style="color: green">{% blocktranslate %}Please correct the errors
below.{% endblocktranslate %}</p>
<p style="color: red">{% blocktranslate count counter=1 %}Please correct
the error below.{% plural %}Please correct the errors below.{%
endblocktranslate %}</p>
<p style="color: red">{% blocktranslate count counter=2 %}Please correct
the error below.{% plural %}Please correct the errors below.{%
endblocktranslate %}</p>
<p style="color: red">{% blocktrans count counter=1 %}Please correct the
error below.{% plural %}Please correct the errors below.{% endblocktrans
%}</p>
<p style="color: red">{% blocktrans count counter=2 %}Please correct the
error below.{% plural %}Please correct the errors below.{% endblocktrans
%}</p>
}}}

home/views.py:

{{{
from django.shortcuts import render


def index(request):
return render(request, "home/index.html")
}}}

home/urls.py:

{{{
from django.urls import path

from . import views

urlpatterns = [
path("", views.index, name="index"),
]
}}}

blocktranstest/urls.py:

{{{
from django.contrib import admin
from django.urls import include, path

urlpatterns = [
path("", include("home.urls")),
path("admin/", admin.site.urls),
]
}}}

{{{
./manage.py runserver
}}}

The index page shows that the first 4 sentences are translated correctly
to Dutch, but the last 4 sentences are still in English (although the
correct pluralised sentences are used):

{{{
Corrigeer de fout hieronder.
Corrigeer de fouten hieronder.
Corrigeer de fout hieronder.
Corrigeer de fouten hieronder.
Please correct the error below.
Please correct the errors below.
Please correct the error below.
Please correct the errors below.
}}}

The expected output is:

{{{
Corrigeer de fout hieronder.
Corrigeer de fouten hieronder.
Corrigeer de fout hieronder.
Corrigeer de fouten hieronder.
Corrigeer de fout hieronder.
Corrigeer de fouten hieronder.
Corrigeer de fout hieronder.
Corrigeer de fouten hieronder.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/35698>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Aug 21, 2024, 9:32:46 AM8/21/24
to django-...@googlegroups.com
#35698: Pluralised blocktranslate doesn't translate
-------------------------------------+-------------------------------------
Reporter: Joris Hartog | Owner: (none)
Type: Uncategorized | Status: closed
Component: | Version: 4.2
Internationalization |
Severity: Normal | Resolution: invalid
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Natalia Bidart):

* resolution: => invalid
* status: new => closed

Comment:

Hello Joris Hartog, thank you for your ticket. Django 4.2 no longer
receives code fixes, only security fixes are considered. Could you please
try to reproduce on the latest supported version which is `5.1`?

My analysis shows that this would not be reproducible in `5.1`, since I
believe that the issue you are reporting is caused by the translation file
not declaring the plural form in `4.2`.
Please compare:
*
[https://github.com/django/django/blob/main/django/contrib/admin/locale/nl/LC_MESSAGES/django.po#L385
the nl translations in `main`] (which is the same for `5.1`), vs
*
[https://github.com/django/django/blob/stable/4.2.x/django/contrib/admin/locale/nl/LC_MESSAGES/django.po#L385
the same translations in `stable/4.2.x`].
--
Ticket URL: <https://code.djangoproject.com/ticket/35698#comment:1>

Django

unread,
Aug 21, 2024, 10:16:24 AM8/21/24
to django-...@googlegroups.com
#35698: Pluralised blocktranslate doesn't translate
-------------------------------------+-------------------------------------
Reporter: Joris Hartog | Owner: (none)
Type: Uncategorized | Status: closed
Component: | Version: 4.2
Internationalization |
Severity: Normal | Resolution: invalid
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Claude Paroz):

FYI the proper pluralization of those messages was introduced in
https://github.com/django/django/commit/36cd4259438f98, so for Django 4.2,
however I guess the `nl` translation wasn't updated on Transifex in time
to enter 4.2.

Please verify before each major Django release that your language is fully
translated on Transifex, if you don't want such issues to happen in the
future.
--
Ticket URL: <https://code.djangoproject.com/ticket/35698#comment:2>
Reply all
Reply to author
Forward
0 new messages