Translations cleanup

This commit is contained in:
Jeremy Stretch 2023-10-24 17:15:20 -04:00
parent 30ce9edf1c
commit 701870d919
9 changed files with 53 additions and 31 deletions

View File

@ -80,10 +80,10 @@ class RackWidthChoices(ChoiceSet):
WIDTH_23IN = 23 WIDTH_23IN = 23
CHOICES = ( CHOICES = (
(WIDTH_10IN, _('10 inches')), (WIDTH_10IN, _('{n} inches').format(n=10)),
(WIDTH_19IN, _('19 inches')), (WIDTH_19IN, _('{n} inches').format(n=19)),
(WIDTH_21IN, _('21 inches')), (WIDTH_21IN, _('{n} inches').format(n=21)),
(WIDTH_23IN, _('23 inches')), (WIDTH_23IN, _('{n} inches').format(n=23)),
) )

View File

@ -534,14 +534,16 @@ class FrontPortTemplate(ModularComponentTemplateModel):
# Validate rear port assignment # Validate rear port assignment
if self.rear_port.device_type != self.device_type: if self.rear_port.device_type != self.device_type:
raise ValidationError( raise ValidationError(
_("Rear port ({}) must belong to the same device type").format(self.rear_port) _("Rear port ({name}) must belong to the same device type").format(name=self.rear_port)
) )
# Validate rear port position assignment # Validate rear port position assignment
if self.rear_port_position > self.rear_port.positions: if self.rear_port_position > self.rear_port.positions:
raise ValidationError( raise ValidationError(
_("Invalid rear port position ({}); rear port {} has only {} positions").format( _("Invalid rear port position ({position}); rear port {name} has only {count} positions").format(
self.rear_port_position, self.rear_port.name, self.rear_port.positions position=self.rear_port_position,
name=self.rear_port.name,
count=self.rear_port.positions
) )
) )

View File

@ -302,8 +302,13 @@ class DeviceType(ImageAttachmentsMixin, PrimaryModel, WeightMixin):
) )
if d.position not in u_available: if d.position not in u_available:
raise ValidationError({ raise ValidationError({
'u_height': _("Device {} in rack {} does not have sufficient space to accommodate a height of " 'u_height': _(
"{}U").format(d, d.rack, self.u_height) "Device {device} in rack {rack} does not have sufficient space to accommodate a "
"height of {height}U"
).format(
device=d,
rack=d.rack,
height=self.u_height)
}) })
# If modifying the height of an existing DeviceType to 0U, check for any instances assigned to a rack position. # If modifying the height of an existing DeviceType to 0U, check for any instances assigned to a rack position.

View File

@ -562,9 +562,9 @@ class RackReservation(PrimaryModel):
invalid_units = [u for u in self.units if u not in self.rack.units] invalid_units = [u for u in self.units if u not in self.rack.units]
if invalid_units: if invalid_units:
raise ValidationError({ raise ValidationError({
'units': _("Invalid unit(s) for {}U rack: {}").format( 'units': _("Invalid unit(s) for {height}U rack: {unit_list}").format(
self.rack.u_height, height=self.rack.u_height,
', '.join([str(u) for u in invalid_units]), unit_list=', '.join([str(u) for u in invalid_units])
), ),
}) })
@ -575,8 +575,8 @@ class RackReservation(PrimaryModel):
conflicting_units = [u for u in self.units if u in reserved_units] conflicting_units = [u for u in self.units if u in reserved_units]
if conflicting_units: if conflicting_units:
raise ValidationError({ raise ValidationError({
'units': _('The following units have already been reserved: {}').format( 'units': _('The following units have already been reserved: {unit_list}').format(
', '.join([str(u) for u in conflicting_units]), unit_list=', '.join([str(u) for u in conflicting_units])
) )
}) })

View File

@ -140,8 +140,11 @@ class Aggregate(GetAvailablePrefixesMixin, PrimaryModel):
if covering_aggregates: if covering_aggregates:
raise ValidationError({ raise ValidationError({
'prefix': _( 'prefix': _(
"Aggregates cannot overlap. {} is already covered by an existing aggregate ({})." "Aggregates cannot overlap. {prefix} is already covered by an existing aggregate ({aggregate})."
).format(self.prefix, covering_aggregates[0]) ).format(
prefix=self.prefix,
aggregate=covering_aggregates[0]
)
}) })
# Ensure that the aggregate being added does not cover an existing aggregate # Ensure that the aggregate being added does not cover an existing aggregate
@ -150,8 +153,11 @@ class Aggregate(GetAvailablePrefixesMixin, PrimaryModel):
covered_aggregates = covered_aggregates.exclude(pk=self.pk) covered_aggregates = covered_aggregates.exclude(pk=self.pk)
if covered_aggregates: if covered_aggregates:
raise ValidationError({ raise ValidationError({
'prefix': _("Aggregates cannot overlap. {} covers an existing aggregate ({}).").format( 'prefix': _(
self.prefix, covered_aggregates[0] "Prefixes cannot overlap aggregates. {prefix} covers an existing aggregate ({aggregate})."
).format(
prefix=self.prefix,
aggregate=covered_aggregates[0]
) )
}) })
@ -314,10 +320,11 @@ class Prefix(GetAvailablePrefixesMixin, PrimaryModel):
if (self.vrf is None and get_config().ENFORCE_GLOBAL_UNIQUE) or (self.vrf and self.vrf.enforce_unique): if (self.vrf is None and get_config().ENFORCE_GLOBAL_UNIQUE) or (self.vrf and self.vrf.enforce_unique):
duplicate_prefixes = self.get_duplicates() duplicate_prefixes = self.get_duplicates()
if duplicate_prefixes: if duplicate_prefixes:
table = _("VRF {vrf}").format(vrf=self.vrf) if self.vrf else _("global table")
raise ValidationError({ raise ValidationError({
'prefix': _("Duplicate prefix found in {}: {}").format( 'prefix': _("Duplicate prefix found in {table}: {prefix}").format(
_("VRF {}").format(self.vrf) if self.vrf else _("global table"), table=table,
duplicate_prefixes.first(), prefix=duplicate_prefixes.first(),
) )
}) })
@ -843,10 +850,11 @@ class IPAddress(PrimaryModel):
self.role not in IPADDRESS_ROLES_NONUNIQUE or self.role not in IPADDRESS_ROLES_NONUNIQUE or
any(dip.role not in IPADDRESS_ROLES_NONUNIQUE for dip in duplicate_ips) any(dip.role not in IPADDRESS_ROLES_NONUNIQUE for dip in duplicate_ips)
): ):
table = _("VRF {}").format(self.vrf) if self.vrf else _("global table")
raise ValidationError({ raise ValidationError({
'address': _("Duplicate IP address found in {}: {}").format( 'address': _("Duplicate IP address found in {table}: {ipaddress}").format(
_("VRF {}").format(self.vrf) if self.vrf else _("global table"), table=table,
duplicate_ips.first(), ipaddress=duplicate_ips.first(),
) )
}) })

View File

@ -1,4 +1,4 @@
from django.utils.translation import gettext as _ from django.utils.translation import gettext_lazy as _
from netbox.registry import registry from netbox.registry import registry
from utilities.choices import ButtonColorChoices from utilities.choices import ButtonColorChoices

View File

@ -8,8 +8,8 @@
{% block message %} {% block message %}
<p> <p>
{% blocktrans trimmed %} {% blocktrans trimmed with device=devicebay.device %}
Are you sure you want to delete this device bay from <strong>{{ devicebay.device }}</strong>? Are you sure you want to delete this device bay from <strong>{{ device }}</strong>?
{% endblocktrans %} {% endblocktrans %}
</p> </p>
{% endblock %} {% endblock %}

View File

@ -151,8 +151,12 @@ class ClusterAddDevicesForm(BootstrapMixin, forms.Form):
for device in self.cleaned_data.get('devices', []): for device in self.cleaned_data.get('devices', []):
if device.site != self.cluster.site: if device.site != self.cluster.site:
raise ValidationError({ raise ValidationError({
'devices': _("{} belongs to a different site ({}) than the cluster ({})").format( 'devices': _(
device, device.site, self.cluster.site "{device} belongs to a different site ({site}) than the cluster ({cluster_site})"
).format(
device=device,
site=device.site,
cluster_site=self.cluster.site
) )
}) })

View File

@ -138,7 +138,10 @@ class Cluster(ContactsMixin, PrimaryModel):
nonsite_devices = Device.objects.filter(cluster=self).exclude(site=self.site).count() nonsite_devices = Device.objects.filter(cluster=self).exclude(site=self.site).count()
if nonsite_devices: if nonsite_devices:
raise ValidationError({ raise ValidationError({
'site': _("{} devices are assigned as hosts for this cluster but are not in site {}").format( 'site': _(
nonsite_devices, self.site "{count} devices are assigned as hosts for this cluster but are not in site {site}"
).format(
count=nonsite_devices,
site=self.site
) )
}) })