Open afranke opened 3 weeks ago
I only mentioned one string because it’s the one I could find, but there may be other ones that are affected by this issue.
And of course right after I post that comment, I find more:
netbox/virtualization/models/clusters.py
has "{count} devices are assigned as hosts for this cluster but are not in site {site}"
netbox/utilities/error_handlers.py
has "Unable to delete <strong>{objects}</strong>. {count} dependent objects were found: "
netbox/utilities/forms/utils.py
has "Row {row}: Expected {count_expected} columns but found {count_found}"
netbox/dcim/models/device_component_templates.py
has "Invalid rear port position ({position}); rear port {name} has only {count} positions"
I may still be missing some more.
@afranke thanks for bringing this to our attention. Would you be willing to contribute a PR to make the proposed changes?
I’m sorry but I won’t be able to. I can review a PR to check if it’s doing the right thing from an i18n perspective though.
Could you please assign it to me?
@afranke In this case In netbox/dcim/views.py if we used the line:
messages.success(request, _(ngettext(
"Disconnected 1 {type}",
"Disconnected {count} {type_plural}",
count,
)).format(
count=count,
type=self.queryset.model._meta.verbose_name,
type_plural=self.queryset.model._meta.verbose_name_plural
))
Would that work for pluralization as you mentioned for Polish? We just have the singular and pluralized model name.
No, it wouldn’t work. See point 2 in the issue description.
Proposed Changes
netbox/dcim/views.py
has_("Disconnected {count} {type}")
wherecount
is as far as I can tell an arbitrary number andtype
a pre-baked plural. This cannot be properly translated in some languages, because plurals don’t work the same way as they do in English.You need to:
ngettext
for the count part, so plural forms can be handled properly.This would result in something along the lines of
with something like a switch-case to match a given type with a given ngettext call.
Sorry for using client and device instead of actual types, I couldn’t easily find the type list.
Justification
You shouldn’t make up your own plural handling. There are tools for that, and good reasons to use them.
See #16659 for a similar but different situation.