mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-11-29 08:25:10 +00:00
help: Add translation contribution prompt for manual pages
Closes: #2341. Tests: - Accessing page /freedombox/help/manual/fr/Users shows an info message about missing translation. The link points to wiki.debian.org/FreedomBox/Manual. Refreshing the page does not show the message again. The message is shown with proper styling of info message even in dark mode. Signed-off-by: Frederico Gomes <fredericojfgomes@gmail.com> [sunil: Use wiki URL instead of weblate URL] [sunil: Use info message instead of warning message] [sunil: Use styling compatible with dark mode] [sunil: Work well with messages middleware in tests] Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
1 parent
bb1a45ef0a
commit
710ab277bb
3 files changed
+57
No files matched your search
@@ -59,6 +59,26 @@ def pytest_collection_modifyitems(config, items):
|
||||
'Set EXTENDED_TESTING=1 to force run'))
|
||||
|
||||
|
||||
@pytest.fixture(name='rf')
|
||||
def fixture_rf():
|
||||
"""Override pytest-django's rf to accommodate storing messages."""
|
||||
from django.contrib.messages.storage.fallback import FallbackStorage
|
||||
from django.test import RequestFactory
|
||||
|
||||
class RequestFactoryWithMessages(RequestFactory):
|
||||
"""Add message storage to each request created."""
|
||||
|
||||
def generic(self, *args, **kwargs):
|
||||
"""Construct an arbitrary HTTP request with message storage."""
|
||||
request = super().generic(*args, **kwargs)
|
||||
setattr(request, 'session', 'session')
|
||||
messages = FallbackStorage(request)
|
||||
setattr(request, '_messages', messages)
|
||||
return request
|
||||
|
||||
return RequestFactoryWithMessages()
|
||||
|
||||
|
||||
@pytest.fixture(name='load_cfg')
|
||||
def fixture_load_cfg():
|
||||
"""Load test configuration."""
|
||||
|
||||
@@ -334,3 +334,31 @@ def test_download_full_manual_file(rf, tmp_path):
|
||||
|
||||
_diff('fallback.pdf', 'unspecified.pdf', same=True)
|
||||
_diff('fallback.pdf', 'translated.pdf', same=False)
|
||||
|
||||
|
||||
def test_missing_manual_page_shows_message(client):
|
||||
"""Test that a message is shown when a manual page is missing.
|
||||
|
||||
Expected:
|
||||
- The user is redirected to the English version of the page.
|
||||
- A warning message is displayed indicating the page is missing in the
|
||||
requested language and providing a link to translation resources.
|
||||
"""
|
||||
page = 'Coturn'
|
||||
lang = 'unknown'
|
||||
manual_url = urls.reverse('help:manual-page', kwargs={
|
||||
'lang': lang,
|
||||
'page': page
|
||||
})
|
||||
|
||||
response = client.get(manual_url)
|
||||
|
||||
assert response.status_code == 302
|
||||
assert response.url.endswith(f'/help/manual/en/{page}')
|
||||
|
||||
storage = response.wsgi_request._messages
|
||||
messages = list(storage._queued_messages)
|
||||
assert len(messages) == 1
|
||||
message = messages[0].message
|
||||
assert 'https://wiki.debian.org/FreedomBox/Manual' in message
|
||||
assert 'translate it' in message
|
||||
@@ -9,10 +9,12 @@ import pathlib
|
||||
|
||||
import apt
|
||||
import requests
|
||||
from django.contrib import messages
|
||||
from django.core.files.base import File
|
||||
from django.http import Http404, HttpResponse, HttpResponseRedirect
|
||||
from django.template.response import TemplateResponse
|
||||
from django.urls import reverse
|
||||
from django.utils.safestring import mark_safe
|
||||
from django.utils.translation import get_language_from_request
|
||||
from django.utils.translation import gettext as _
|
||||
|
||||
@@ -123,6 +125,13 @@ def manual(request, lang=None, page=None):
|
||||
content = read_file(lang, f'{page}.part.html')
|
||||
if not content:
|
||||
if lang != 'en':
|
||||
url = 'https://wiki.debian.org/FreedomBox/Manual'
|
||||
messages.info(
|
||||
request,
|
||||
mark_safe(
|
||||
_('This manual page is not available in your language. '
|
||||
'Help <a href="%(url)s">translate it</a>.') %
|
||||
{'url': url}))
|
||||
return HttpResponseRedirect(
|
||||
reverse('help:manual-page', kwargs=dict(lang='en', page=page)))
|
||||
|
||||
|
||||
Reference in new issue
Block a user