diff --git a/netbox/utilities/error_handlers.py b/netbox/utilities/error_handlers.py
index 386ec6f39..e1e016e71 100644
--- a/netbox/utilities/error_handlers.py
+++ b/netbox/utilities/error_handlers.py
@@ -7,7 +7,7 @@ from django.db.models import ProtectedError, RestrictedError
from django.http import JsonResponse
from django.utils.html import escape
from django.utils.safestring import mark_safe
-from django.utils.translation import gettext_lazy as _
+from django.utils.translation import gettext_lazy as _, ngettext
from rest_framework import status
__all__ = (
@@ -28,7 +28,10 @@ def handle_protectederror(obj_list, request, e):
raise e
# Formulate the error message
- err_message = _("Unable to delete {objects}. {count} dependent objects were found: ").format(
+ err_message = _(ngettext(
+ "Unable to delete {objects}. {count} dependent object was found: ",
+ "Unable to delete {objects}. {count} dependent objects were found: ",
+ len(protected_objects),)).format(
objects=', '.join(str(obj) for obj in obj_list),
count=len(protected_objects) if len(protected_objects) <= 50 else _('More than 50')
)
diff --git a/netbox/virtualization/models/clusters.py b/netbox/virtualization/models/clusters.py
index f8acc4c36..127d35973 100644
--- a/netbox/virtualization/models/clusters.py
+++ b/netbox/virtualization/models/clusters.py
@@ -2,7 +2,7 @@ from django.contrib.contenttypes.fields import GenericRelation
from django.core.exceptions import ValidationError
from django.db import models
from django.urls import reverse
-from django.utils.translation import gettext_lazy as _
+from django.utils.translation import gettext_lazy as _, ngettext
from dcim.models import Device
from netbox.models import OrganizationalModel, PrimaryModel
@@ -137,7 +137,9 @@ class Cluster(ContactsMixin, PrimaryModel):
if self.pk and self.site:
if nonsite_devices := Device.objects.filter(cluster=self).exclude(site=self.site).count():
raise ValidationError({
- 'site': _(
- "{count} devices are assigned as hosts for this cluster but are not in site {site}"
- ).format(count=nonsite_devices, site=self.site)
+ 'site': _(ngettext(
+ "{count} device is assigned as hosts for this cluster but is not in site {site}",
+ "{count} devices are assigned as hosts for this cluster but are not in site {site}",
+ nonsite_devices,
+ )).format(count=nonsite_devices, site=self.site)
})