1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-11-11 12:46:49 +00:00

fix(locale): the VM page's and Settings page's messages show translated

The VM page's and the Settings page's views marked their messages with
gettext_noop, so every message they gave (a refused resize, a saved
setting, a QoS change, a busy VM) showed in English whatever the
language, though the catalogs translate them. They translate in the
request's language now; their module-level texts lazily. The Settings
page's group titles stay English in the view, as the page links them
by their slugs and translates them itself.

Two values went into translated messages as English codes: a job's
state ("... is running on this resource") and a QoS direction ("Remove
the inbound limit ..."). They are named as the pages name them.
This commit is contained in:
catborise 2026-11-02 23:09:05 +03:00
parent 763f1525ca
commit 9d57adc097
10 changed files with 412 additions and 380 deletions

View file

@ -1,6 +1,7 @@
{% load i18n %}
{# one QoS limit of a NIC: its values to change, or to delete #}
<form class="mt-2" style="max-width: 32rem" action="{% url 'instances:set_qos' instance.id %}" method="post" aria-label="{% blocktrans %}{{ direction }} QoS form{% endblocktrans %}">{% csrf_token %}
{% if direction == "inbound" %}{% trans "inbound" as direction_name %}{% else %}{% trans "outbound" as direction_name %}{% endif %}
<form class="mt-2" style="max-width: 32rem" action="{% url 'instances:set_qos' instance.id %}" method="post" aria-label="{% blocktrans with direction=direction_name %}{{ direction }} QoS form{% endblocktrans %}">{% csrf_token %}
<input type="hidden" name="net-mac" value="{{ network.mac }}">
<input type="hidden" name="qos_direction" value="{{ direction }}">
<div class="fw-semibold mb-1">{% if direction == "inbound" %}{% trans "Inbound" %}{% else %}{% trans "Outbound" %}{% endif %}</div>
@ -21,6 +22,6 @@
<div class="d-flex flex-wrap gap-2 mt-2">
<button type="submit" class="btn btn-sm btn-primary" name="set_qos">{% trans "Save" %}</button>
<button type="submit" class="btn btn-sm btn-danger" name="unset_qos" formaction="{% url 'instances:unset_qos' instance.id %}" formnovalidate
data-confirm="{% blocktrans with mac=network.mac %}Remove the {{ direction }} limit of {{ mac }}? A running VM keeps it until it is powered off and on.{% endblocktrans %}">{% trans "Delete limit" %}</button>
data-confirm="{% blocktrans with direction=direction_name mac=network.mac %}Remove the {{ direction }} limit of {{ mac }}? A running VM keeps it until it is powered off and on.{% endblocktrans %}">{% trans "Delete limit" %}</button>
</div>
</form>

View file

@ -35,7 +35,8 @@ from django.shortcuts import get_object_or_404, redirect, render
from django.urls import reverse
from django.template.defaultfilters import filesizeformat
from django.utils import timezone
from django.utils.translation import gettext_noop as _
from django.utils.translation import gettext as _
from django.utils.translation import gettext_lazy
from django.views.decorators.http import require_POST
from libvirt import (VIR_DOMAIN_PAUSED,
VIR_DOMAIN_RUNNING,
@ -741,11 +742,11 @@ def invalid_disk_options(
# libvirt's words when a running q35 VM has no free root port for a PCIe device
PCI_SLOTS_FULL = "No more available PCI slots"
# a disk on the scsi bus needs no slot of its own when the VM already has a SCSI controller
DISK_NO_PCI_SLOT = _("The running VM has no free PCI slot for another disk on this bus: choose the scsi bus "
DISK_NO_PCI_SLOT = gettext_lazy("The running VM has no free PCI slot for another disk on this bus: choose the scsi bus "
"if the VM has a SCSI controller, or shut the VM down and add the disk then; Add PCIe slots "
"on the Disks tab gives it free ones from its next start. A new volume stays in its pool, "
"to attach as an existing volume.")
SCSI_NO_PCI_SLOT = _("The running VM has no free PCI slot for the SCSI controller the disk needs: shut the VM "
SCSI_NO_PCI_SLOT = gettext_lazy("The running VM has no free PCI slot for the SCSI controller the disk needs: shut the VM "
"down and add the disk then; Add PCIe slots on the Disks tab gives it free ones from its next "
"start. A new volume stays in its pool, to attach as an existing volume.")
@ -1059,7 +1060,7 @@ def gstfsd_request(compute, data):
# root password and SSH key: gstfsd changes a shut-off VM's disk, the QEMU
# guest agent a running VM
AGENT_OR_SHUT_OFF = _("Shut the VM down, or start its QEMU guest agent, and try again")
AGENT_OR_SHUT_OFF = gettext_lazy("Shut the VM down, or start its QEMU guest agent, and try again")
# libvirt's value; bindings built against older libvirt (Ubuntu 24.04's) lack
@ -2207,13 +2208,13 @@ def set_qos(request, pk):
instance.proxy.set_qos(mac, qos_dir, average, peak, burst)
if instance.proxy.get_status() == 5:
messages.success(
request, _("%(qos_dir)s QoS is set") % {"qos_dir": qos_dir.capitalize()}
request, _("%(qos_dir)s QoS is set") % {"qos_dir": _(qos_dir.capitalize())}
)
else:
messages.success(
request,
_("%(qos_dir)s QoS is set. A running VM gets it after it is powered off and on.")
% {"qos_dir": qos_dir.capitalize()},
% {"qos_dir": _(qos_dir.capitalize())},
)
return _back(request, pk, "network")
@ -2234,13 +2235,13 @@ def unset_qos(request, pk):
if instance.proxy.get_status() == 5:
messages.success(
request, _("%(qos_dir)s QoS is deleted") % {"qos_dir": qos_dir.capitalize()}
request, _("%(qos_dir)s QoS is deleted") % {"qos_dir": _(qos_dir.capitalize())}
)
else:
messages.success(
request,
_("%(qos_dir)s QoS is deleted. A running VM keeps the old limit until it is powered off and on.")
% {"qos_dir": qos_dir.capitalize()},
% {"qos_dir": _(qos_dir.capitalize())},
)
return _back(request, pk, "network")
@ -2492,9 +2493,9 @@ def create_instance_select_type(request, compute_id):
# the create form's disk sources: (value, title, help)
DISK_SOURCES = [
("new", _("New disk"), _("An empty disk of the size you set")),
("existing", _("Existing volumes"), _("Volumes already in a pool")),
("template", _("Clone from template"), _("A copy of a template volume")),
("new", gettext_lazy("New disk"), gettext_lazy("An empty disk of the size you set")),
("existing", gettext_lazy("Existing volumes"), gettext_lazy("Volumes already in a pool")),
("template", gettext_lazy("Clone from template"), gettext_lazy("A copy of a template volume")),
]