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 -8
View File
@@ -4,8 +4,7 @@
import re
import subprocess
from django.utils.text import format_lazy
from django.utils.translation import gettext_lazy
from django.utils.translation import gettext_noop
from plinth import action_utils, app
from plinth.modules.diagnostics.check import DiagnosticCheck, Result
@@ -149,16 +148,13 @@ def diagnose_url(url, kind=None, env=None, check_certificate=True,
except FileNotFoundError:
result = Result.ERROR
parameters = {'url': url}
parameters = {'url': url, 'kind': kind}
if kind:
parameters['kind'] = kind
check_id = f'apache-url-kind-{url}-{kind}'
template = gettext_lazy('Access URL {url} on tcp{kind}')
description = format_lazy(template, url=url, kind=kind)
description = gettext_noop('Access URL {url} on tcp{kind}')
else:
check_id = f'apache-url-{url}'
template = gettext_lazy('Access URL {url}')
description = format_lazy(template, url=url)
description = gettext_noop('Access URL {url}')
return DiagnosticCheck(check_id, description, result, parameters)
@@ -12,7 +12,8 @@ from plinth import app
from plinth.modules.apache.components import (Uwsgi, Webserver, check_url,
diagnose_url,
diagnose_url_on_all)
from plinth.modules.diagnostics.check import DiagnosticCheck, Result
from plinth.modules.diagnostics.check import (DiagnosticCheck, Result,
translate, translate_checks)
def test_webserver_init():
@@ -248,13 +249,13 @@ def test_diagnose_url(get_addresses, check):
}
parameters = {key: args[key] for key in ['url', 'kind']}
check.return_value = True
result = diagnose_url(**args)
result = translate(diagnose_url(**args))
assert result == DiagnosticCheck(
'apache-url-kind-https://localhost/test-4',
'Access URL https://localhost/test on tcp4', Result.PASSED, parameters)
check.return_value = False
result = diagnose_url(**args)
result = translate(diagnose_url(**args))
assert result == DiagnosticCheck(
'apache-url-kind-https://localhost/test-4',
'Access URL https://localhost/test on tcp4', Result.FAILED, parameters)
@@ -283,7 +284,7 @@ def test_diagnose_url(get_addresses, check):
'kind': '6'
},
]
results = diagnose_url_on_all(**args)
results = translate_checks(diagnose_url_on_all(**args))
assert results == [
DiagnosticCheck('apache-url-kind-https://test-host-1/test-4',
'Access URL https://test-host-1/test on tcp4',