From 701870d91944679ecc056e48c674eeaf35c4de10 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Tue, 24 Oct 2023 17:15:20 -0400 Subject: [PATCH] Translations cleanup --- netbox/dcim/choices.py | 8 +++--- .../dcim/models/device_component_templates.py | 8 ++++-- netbox/dcim/models/devices.py | 9 ++++-- netbox/dcim/models/racks.py | 10 +++---- netbox/ipam/models/ip.py | 28 ++++++++++++------- netbox/netbox/navigation/menu.py | 2 +- netbox/templates/dcim/devicebay_delete.html | 4 +-- netbox/virtualization/forms/model_forms.py | 8 ++++-- netbox/virtualization/models/clusters.py | 7 +++-- 9 files changed, 53 insertions(+), 31 deletions(-) diff --git a/netbox/dcim/choices.py b/netbox/dcim/choices.py index e1d4a330a..2ba24e0aa 100644 --- a/netbox/dcim/choices.py +++ b/netbox/dcim/choices.py @@ -80,10 +80,10 @@ class RackWidthChoices(ChoiceSet): WIDTH_23IN = 23 CHOICES = ( - (WIDTH_10IN, _('10 inches')), - (WIDTH_19IN, _('19 inches')), - (WIDTH_21IN, _('21 inches')), - (WIDTH_23IN, _('23 inches')), + (WIDTH_10IN, _('{n} inches').format(n=10)), + (WIDTH_19IN, _('{n} inches').format(n=19)), + (WIDTH_21IN, _('{n} inches').format(n=21)), + (WIDTH_23IN, _('{n} inches').format(n=23)), ) diff --git a/netbox/dcim/models/device_component_templates.py b/netbox/dcim/models/device_component_templates.py index 86b6d85fe..5110835f4 100644 --- a/netbox/dcim/models/device_component_templates.py +++ b/netbox/dcim/models/device_component_templates.py @@ -534,14 +534,16 @@ class FrontPortTemplate(ModularComponentTemplateModel): # Validate rear port assignment if self.rear_port.device_type != self.device_type: 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 if self.rear_port_position > self.rear_port.positions: raise ValidationError( - _("Invalid rear port position ({}); rear port {} has only {} positions").format( - self.rear_port_position, self.rear_port.name, self.rear_port.positions + _("Invalid rear port position ({position}); rear port {name} has only {count} positions").format( + position=self.rear_port_position, + name=self.rear_port.name, + count=self.rear_port.positions ) ) diff --git a/netbox/dcim/models/devices.py b/netbox/dcim/models/devices.py index 943bf318c..b8ced52de 100644 --- a/netbox/dcim/models/devices.py +++ b/netbox/dcim/models/devices.py @@ -302,8 +302,13 @@ class DeviceType(ImageAttachmentsMixin, PrimaryModel, WeightMixin): ) if d.position not in u_available: raise ValidationError({ - 'u_height': _("Device {} in rack {} does not have sufficient space to accommodate a height of " - "{}U").format(d, d.rack, self.u_height) + '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. diff --git a/netbox/dcim/models/racks.py b/netbox/dcim/models/racks.py index ab1027d1b..0d4b844f9 100644 --- a/netbox/dcim/models/racks.py +++ b/netbox/dcim/models/racks.py @@ -562,9 +562,9 @@ class RackReservation(PrimaryModel): invalid_units = [u for u in self.units if u not in self.rack.units] if invalid_units: raise ValidationError({ - 'units': _("Invalid unit(s) for {}U rack: {}").format( - self.rack.u_height, - ', '.join([str(u) for u in invalid_units]), + 'units': _("Invalid unit(s) for {height}U rack: {unit_list}").format( + height=self.rack.u_height, + 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] if conflicting_units: raise ValidationError({ - 'units': _('The following units have already been reserved: {}').format( - ', '.join([str(u) for u in conflicting_units]), + 'units': _('The following units have already been reserved: {unit_list}').format( + unit_list=', '.join([str(u) for u in conflicting_units]) ) }) diff --git a/netbox/ipam/models/ip.py b/netbox/ipam/models/ip.py index d176d3bff..322e1f7ae 100644 --- a/netbox/ipam/models/ip.py +++ b/netbox/ipam/models/ip.py @@ -140,8 +140,11 @@ class Aggregate(GetAvailablePrefixesMixin, PrimaryModel): if covering_aggregates: raise ValidationError({ 'prefix': _( - "Aggregates cannot overlap. {} is already covered by an existing aggregate ({})." - ).format(self.prefix, covering_aggregates[0]) + "Aggregates cannot overlap. {prefix} is already covered by an existing aggregate ({aggregate})." + ).format( + prefix=self.prefix, + aggregate=covering_aggregates[0] + ) }) # 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) if covered_aggregates: raise ValidationError({ - 'prefix': _("Aggregates cannot overlap. {} covers an existing aggregate ({}).").format( - self.prefix, covered_aggregates[0] + 'prefix': _( + "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): duplicate_prefixes = self.get_duplicates() if duplicate_prefixes: + table = _("VRF {vrf}").format(vrf=self.vrf) if self.vrf else _("global table") raise ValidationError({ - 'prefix': _("Duplicate prefix found in {}: {}").format( - _("VRF {}").format(self.vrf) if self.vrf else _("global table"), - duplicate_prefixes.first(), + 'prefix': _("Duplicate prefix found in {table}: {prefix}").format( + table=table, + prefix=duplicate_prefixes.first(), ) }) @@ -843,10 +850,11 @@ class IPAddress(PrimaryModel): self.role not in IPADDRESS_ROLES_NONUNIQUE or 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({ - 'address': _("Duplicate IP address found in {}: {}").format( - _("VRF {}").format(self.vrf) if self.vrf else _("global table"), - duplicate_ips.first(), + 'address': _("Duplicate IP address found in {table}: {ipaddress}").format( + table=table, + ipaddress=duplicate_ips.first(), ) }) diff --git a/netbox/netbox/navigation/menu.py b/netbox/netbox/navigation/menu.py index 5b64cfc1e..961fd2035 100644 --- a/netbox/netbox/navigation/menu.py +++ b/netbox/netbox/navigation/menu.py @@ -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 utilities.choices import ButtonColorChoices diff --git a/netbox/templates/dcim/devicebay_delete.html b/netbox/templates/dcim/devicebay_delete.html index 18f4f6576..9e54baa86 100644 --- a/netbox/templates/dcim/devicebay_delete.html +++ b/netbox/templates/dcim/devicebay_delete.html @@ -8,8 +8,8 @@ {% block message %}

- {% blocktrans trimmed %} - Are you sure you want to delete this device bay from {{ devicebay.device }}? + {% blocktrans trimmed with device=devicebay.device %} + Are you sure you want to delete this device bay from {{ device }}? {% endblocktrans %}

{% endblock %} diff --git a/netbox/virtualization/forms/model_forms.py b/netbox/virtualization/forms/model_forms.py index 21dbc895a..79b8c04ec 100644 --- a/netbox/virtualization/forms/model_forms.py +++ b/netbox/virtualization/forms/model_forms.py @@ -151,8 +151,12 @@ class ClusterAddDevicesForm(BootstrapMixin, forms.Form): for device in self.cleaned_data.get('devices', []): if device.site != self.cluster.site: raise ValidationError({ - 'devices': _("{} belongs to a different site ({}) than the cluster ({})").format( - device, device.site, self.cluster.site + 'devices': _( + "{device} belongs to a different site ({site}) than the cluster ({cluster_site})" + ).format( + device=device, + site=device.site, + cluster_site=self.cluster.site ) }) diff --git a/netbox/virtualization/models/clusters.py b/netbox/virtualization/models/clusters.py index 6c8fd0c4b..717900e31 100644 --- a/netbox/virtualization/models/clusters.py +++ b/netbox/virtualization/models/clusters.py @@ -138,7 +138,10 @@ class Cluster(ContactsMixin, PrimaryModel): nonsite_devices = Device.objects.filter(cluster=self).exclude(site=self.site).count() if nonsite_devices: raise ValidationError({ - 'site': _("{} devices are assigned as hosts for this cluster but are not in site {}").format( - nonsite_devices, self.site + 'site': _( + "{count} devices are assigned as hosts for this cluster but are not in site {site}" + ).format( + count=nonsite_devices, + site=self.site ) })