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

@ -288,6 +288,7 @@
</thead>
<tbody>
{% for direction, limit in qos.items %}
{% if direction == "inbound" %}{% trans "inbound" as direction_name %}{% else %}{% trans "outbound" as direction_name %}{% endif %}
<tr>
<td>{% if direction == "inbound" %}{% trans "Inbound" %}{% else %}{% trans "Outbound" %}{% endif %}</td>
<td>{% if limit.average %}{{ limit.average }} KiB/s{% else %}–{% endif %}</td>
@ -301,7 +302,7 @@
<form method="post" class="btn-group">{% csrf_token %}
<input type="hidden" name="qos_direction" value="{{ direction }}">
<button type="submit" class="btn btn-sm btn-outline-secondary" name="unset_qos" aria-label="{% trans "Remove" %}"
data-confirm="{% blocktrans with name=pool %}Remove the {{ direction }} limit of network {{ name }}? It stays in force until the network is stopped and started.{% endblocktrans %}">{% bs_icon 'trash' %}</button>
data-confirm="{% blocktrans with direction=direction_name name=pool %}Remove the {{ direction }} limit of network {{ name }}? It stays in force until the network is stopped and started.{% endblocktrans %}">{% bs_icon 'trash' %}</button>
</form>
</div>
</td>

View file

@ -221,12 +221,12 @@ def network(request, compute_id, pool):
_(
"%(qos_dir)s QoS is updated. Network XML is changed. Stop and start network to activate new config"
)
% {"qos_dir": qos_dir.capitalize()},
% {"qos_dir": _(qos_dir.capitalize())},
)
else:
messages.success(
request,
_("%(qos_dir)s QoS is set") % {"qos_dir": qos_dir.capitalize()},
_("%(qos_dir)s QoS is set") % {"qos_dir": _(qos_dir.capitalize())},
)
except (libvirtError, ValueError) as err:
messages.error(request, err)
@ -247,12 +247,12 @@ def network(request, compute_id, pool):
"%(qos_dir)s QoS is deleted. Network XML is changed. "
"Stop and start network to activate new config"
)
% {"qos_dir": qos_dir.capitalize()},
% {"qos_dir": _(qos_dir.capitalize())},
)
else:
messages.success(
request,
_("%(qos_dir)s QoS is deleted") % {"qos_dir": qos_dir.capitalize()},
_("%(qos_dir)s QoS is deleted") % {"qos_dir": _(qos_dir.capitalize())},
)
return HttpResponseRedirect(here)
# read only for the page: every action above redirects