From 783b2039f043d37156eb0c8a9697930e63aee2da Mon Sep 17 00:00:00 2001 From: Akihiro Motoki Date: Sun, 1 Oct 2023 17:55:40 +0900 Subject: [PATCH] i18n: Avoid using variables in gettext() in network QoS edit rule If an argument to gettext() contains variables, strings extracted and strings used when rendered will be different (as variables are evaluated as empty during string extraction to POT). As a result, translations for these strings aree never used. This commit fixes the issue by defining strings with variable substitions (like%(id)s) in gettext() combined with interpolate(). Labels of "Rule to edit" pulldown menu in "Edit Rule" form are updated to match the format used in "Delete Rule" form. Closes-Bug: #2037278 Change-Id: I06cb56ada2c842e5a445026b4649260bf9893841 --- .../actions/edit-rule.controller.js | 41 +++++++++++++++---- .../actions/edit-rule.controller.spec.js | 12 ++++-- 2 files changed, 40 insertions(+), 13 deletions(-) diff --git a/openstack_dashboard/static/app/core/network_qos/actions/edit-rule.controller.js b/openstack_dashboard/static/app/core/network_qos/actions/edit-rule.controller.js index 49840d3d69..257e15b05c 100644 --- a/openstack_dashboard/static/app/core/network_qos/actions/edit-rule.controller.js +++ b/openstack_dashboard/static/app/core/network_qos/actions/edit-rule.controller.js @@ -39,30 +39,53 @@ ctrl.rule_types = []; angular.forEach($scope.model.rules, function(k) { if (k.type === 'bandwidth_limit') { - ctrl.rule_types.push({name: 'bandwidth_limit', val: gettext('Bandwidth Limit - ' + - k.id + ', ' + k.max_kbps + ', ' + k.max_burst_kbps + ', ' + k.direction)}); + ctrl.rule_types.push({ + name: 'bandwidth_limit', + val: interpolate( + gettext('%(id)s - Bandwidth Limit - maxkbps: %(max_kbps)s, ' + + 'maxburstkbps: %(max_burst_kb)s, %(direction)s'), + {id: k.id, + max_kbps: k.max_kbps, + max_burst_kb: k.max_burst_kbps, + direction: k.direction}, + true) + }); ctrl.bwdid = k.id; ctrl.maxkbps = k.max_kbps; ctrl.maxburstkbps = k.max_burst_kbps || 0; ctrl.bwddirection = k.direction; } else if (k.type === 'dscp_marking') { - ctrl.rule_types.push({name: 'dscp_marking', - val: gettext("DSCP Mark - " + k.id + ', ' + k.dscp_mark)}); + ctrl.rule_types.push({ + name: 'dscp_marking', + val: interpolate( + gettext("%(id)s - DSCP Marking - dscpmark: %(dscp_mark)s"), + {id: k.id, dscp_mark: k.dscp_mark}, + true) + }); ctrl.dscpid = k.id; ctrl.dscpmark = k.dscp_mark; } else if (k.type === 'minimum_bandwidth') { - ctrl.rule_types.push({name: 'minimum_bandwidth', - val: gettext('Minimum Bandwidth - ' + k.id + ', ' + k.min_kbps + ', ' + k.direction)}); + ctrl.rule_types.push({ + name: 'minimum_bandwidth', + val: interpolate( + gettext('%(id)s - Minimum Bandwidth - minkbps: %(min_kbps)s, %(direction)s'), + {id: k.id, min_kbps: k.min_kbps, direction: k.direction}, + true) + }); ctrl.minbwdid = k.id; ctrl.minkbps = k.min_kbps; ctrl.minbwddirection = k.direction; } else if (k.type === 'minimum_packet_rate') { - ctrl.rule_types.push({name: 'minimum_packet_rate', - val: gettext('Minimum Packet Rate - ' + k.id + ', ' + k.min_kpps + ', ' + - k.direction)}); + ctrl.rule_types.push({ + name: 'minimum_packet_rate', + val: interpolate( + gettext('%(id)s - Minimum Packet Rate - minkpps: %(min_kpps)s, %(direction)s'), + {id: k.id, min_kpps: k.min_kpps, direction: k.direction}, + true) + }); ctrl.minpckrtid = k.id; ctrl.minkpps = k.min_kpps; ctrl.minpckrtdirection = k.direction; diff --git a/openstack_dashboard/static/app/core/network_qos/actions/edit-rule.controller.spec.js b/openstack_dashboard/static/app/core/network_qos/actions/edit-rule.controller.spec.js index 3ba4dc6d7d..70e437262e 100644 --- a/openstack_dashboard/static/app/core/network_qos/actions/edit-rule.controller.spec.js +++ b/openstack_dashboard/static/app/core/network_qos/actions/edit-rule.controller.spec.js @@ -63,10 +63,14 @@ ); rules = [ - {name: "bandwidth_limit", val: "Bandwidth Limit - 1, 1000, 100, egress"}, - {name: "dscp_marking", val: "DSCP Mark - 1, 12"}, - {name: "minimum_bandwidth", val: "Minimum Bandwidth - 1, 100, egress"}, - {name: "minimum_packet_rate", val: "Minimum Packet Rate - 1, 10000, egress"} + {name: "bandwidth_limit", + val: "1 - Bandwidth Limit - maxkbps: 1000, maxburstkbps: 100, egress"}, + {name: "dscp_marking", + val: "1 - DSCP Marking - dscpmark: 12"}, + {name: "minimum_bandwidth", + val: "1 - Minimum Bandwidth - minkbps: 100, egress"}, + {name: "minimum_packet_rate", + val: "1 - Minimum Packet Rate - minkpps: 10000, egress"} ]; directions = { "egress": "egress",