Opened 3 months ago

Closed 3 months ago

Last modified 3 months ago

#35698 closed Uncategorized (invalid)

Pluralised blocktranslate doesn't translate

Reported by: Joris Hartog Owned by:
Component: Internationalization Version: 4.2
Severity: Normal Keywords:
Cc: Joris Hartog Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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.

Change History (2)

comment:1 by Natalia Bidart, 3 months ago

Resolution: invalid
Status: newclosed

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:

comment:2 by Claude Paroz, 3 months ago

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.

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