diagnostics: Translate descriptions only in view

Tests:

- Enable all apps, and run diagnostics. Diagnostic descriptions are formatted
  as expected.

- Change the language to Spanish, and view the diagnostic results. Diagnostic
  descriptions are translated as expected.

Signed-off-by: James Valleroy <jvalleroy@mailbox.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
James Valleroy authored and Sunil Mohan Adapa committed 2024-01-18 22:19:05 -08:00
1 parent a5820bc36d
commit 3fcd6b9e58
18 files changed
+101 -89

No files matched your search

+4 -4
View File
@@ -4,8 +4,8 @@
import contextlib
import logging
from django.utils.translation import gettext
from django.utils.translation import gettext_lazy as _
from django.utils.translation import gettext_noop
from plinth import app as app_module
from plinth import cfg, menu
@@ -268,7 +268,7 @@ def remove_passthrough(ipv, *args):
def _diagnose_default_zone(config):
"""Diagnose whether the default zone is external."""
check_id = 'firewall-default-zone'
description = gettext('Default zone is external')
description = gettext_noop('Default zone is external')
result = Result.PASSED if config[
'default_zone'] == 'external' else Result.FAILED
return DiagnosticCheck(check_id, description, result)
@@ -277,7 +277,7 @@ def _diagnose_default_zone(config):
def _diagnose_firewall_backend(config):
"""Diagnose whether the firewall backend is nftables."""
check_id = 'firewall-backend'
description = gettext('Firewall backend is nftables')
description = gettext_noop('Firewall backend is nftables')
result = Result.PASSED if config['backend'] == 'nftables' \
else Result.FAILED
return DiagnosticCheck(check_id, description, result)
@@ -290,7 +290,7 @@ def _diagnose_direct_passthroughs(config):
which are the number that are added by firewall's setup.
"""
check_id = 'firewall-direct-passthroughs'
description = gettext('Direct passthrough rules exist')
description = gettext_noop('Direct passthrough rules exist')
result = Result.PASSED if len(
config['passthroughs']) >= 12 else Result.FAILED
return DiagnosticCheck(check_id, description, result)
+4 -8
View File
@@ -7,8 +7,7 @@ import logging
import re
from typing import ClassVar
from django.utils.text import format_lazy
from django.utils.translation import gettext_lazy as _
from django.utils.translation import gettext_noop
from plinth import app
from plinth.modules import firewall
@@ -133,9 +132,8 @@ class Firewall(app.FollowerComponent):
# Internal zone
check_id = f'firewall-port-internal-{port}'
result = Result.PASSED if port in internal_ports else Result.FAILED
template = _(
description = gettext_noop(
'Port {name} ({details}) available for internal networks')
description = format_lazy(template, name=port, details=details)
parameters = {'name': port, 'details': details}
results.append(
DiagnosticCheck(check_id, description, result, parameters))
@@ -145,17 +143,15 @@ class Firewall(app.FollowerComponent):
check_id = f'firewall-port-external-available-{port}'
result = Result.PASSED \
if port in external_ports else Result.FAILED
template = _(
description = gettext_noop(
'Port {name} ({details}) available for external networks')
description = format_lazy(template, name=port, details=details)
else:
check_id = f'firewall-port-external-unavailable-{port}'
result = Result.PASSED \
if port not in external_ports else Result.FAILED
template = _(
description = gettext_noop(
'Port {name} ({details}) unavailable for external networks'
)
description = format_lazy(template, name=port, details=details)
parameters = {'name': port, 'details': details}
results.append(
@@ -8,7 +8,8 @@ from unittest.mock import call, patch
import pytest
from plinth.app import App
from plinth.modules.diagnostics.check import DiagnosticCheck, Result
from plinth.modules.diagnostics.check import (DiagnosticCheck, Result,
translate_checks)
from plinth.modules.firewall.components import (Firewall,
FirewallLocalProtection)
@@ -153,7 +154,7 @@ def test_diagnose(get_enabled_services, get_port_details):
get_port_details.side_effect = get_port_details_side_effect
firewall = Firewall('test-firewall-1', ports=['test-port1', 'test-port2'],
is_external=False)
results = firewall.diagnose()
results = translate_checks(firewall.diagnose())
assert results == [
DiagnosticCheck(
'firewall-port-internal-test-port1',
@@ -187,7 +188,7 @@ def test_diagnose(get_enabled_services, get_port_details):
firewall = Firewall('test-firewall-1', ports=['test-port3', 'test-port4'],
is_external=True)
results = firewall.diagnose()
results = translate_checks(firewall.diagnose())
assert results == [
DiagnosticCheck(
'firewall-port-internal-test-port3',