Run permission labels through translation on the permission management template (#11923)

Since `{% trans some_variable %}` cannot be handled by makemessages, we also need to ensure that any string that arises from Wagtail's native permissions, such as "Can access Wagtail admin" or "Can view", exists somewhere in the python code as a `_("...")` value.

Fixes #5341
pull/11927/head
Matt Westcott 2024-05-02 20:18:59 +01:00
rodzic 538365fcfc
commit 8aaa579bef
6 zmienionych plików z 18 dodań i 4 usunięć

Wyświetl plik

@ -9,6 +9,7 @@ Changelog
* Refactor redirects edit view to use the generic `EditView` and breadcrumbs (Rohit Sharma)
* Fix: Make `WAGTAILIMAGES_CHOOSER_PAGE_SIZE` setting functional again (Rohit Sharma)
* Fix: Enable `richtext` template tag to convert lazy translation values (Benjamin Bach)
* Fix: Ensure permission labels on group permissions page are translated where available (Matt Westcott)
* Docs: Remove duplicate section on frontend caching proxies from performance page (Jake Howard)
* Maintenance: Use `DjangoJSONEncoder` instead of custom `LazyStringEncoder` to serialize Draftail config (Sage Abdullah)

Wyświetl plik

@ -22,6 +22,7 @@ depth: 1
* Make `WAGTAILIMAGES_CHOOSER_PAGE_SIZE` setting functional again (Rohit Sharma)
* Enable `richtext` template tag to convert lazy translation values (Benjamin Bach)
* Ensure permission labels on group permissions page are translated where available (Matt Westcott)
### Documentation

Wyświetl plik

@ -1,5 +1,6 @@
from django.contrib.contenttypes.models import ContentType
from django.db.models import Count, Model
from django.utils.translation import gettext_lazy as _
from modelcluster.fields import ParentalKey
from taggit.models import Tag
@ -18,7 +19,7 @@ class Admin(Model):
class Meta:
default_permissions = [] # don't create the default add / change / delete / view perms
permissions = [
("access_admin", "Can access Wagtail admin"),
("access_admin", _("Can access Wagtail admin")),
]

Wyświetl plik

@ -1,5 +1,6 @@
from django.conf import settings
from django.db.models import Model
from django.utils.translation import gettext_lazy as _
from wagtail import hooks
from wagtail.models import Locale
@ -17,7 +18,7 @@ class SimpleTranslation(Model):
class Meta:
default_permissions = []
permissions = [
("submit_translation", "Can submit translations"),
("submit_translation", _("Can submit translations")),
]

Wyświetl plik

@ -96,7 +96,8 @@
<fieldset class="w-p-0">
<legend class="w-sr-only">{% trans "Custom permissions" %}</legend>
{% for custom_perm in content_perms_dict.custom %}
{% include "wagtailadmin/shared/forms/single_checkbox.html" with name="permissions" value=custom_perm.perm.id checked=custom_perm.selected text=custom_perm.name attrs=custom_perm.attrs %}
{% trans custom_perm.name as custom_perm_label %}
{% include "wagtailadmin/shared/forms/single_checkbox.html" with name="permissions" value=custom_perm.perm.id checked=custom_perm.selected text=custom_perm_label attrs=custom_perm.attrs %}
{% endfor %}
</fieldset>
{% endif %}
@ -170,7 +171,7 @@
<tbody>
{% for perm_tuple in other_perms %}
<tr>
<td class="title"><label for="{{ perm_tuple.1.id_for_label }}" class="w-label-3">{{ perm_tuple.0.name }}</label></td>
<td class="title"><label for="{{ perm_tuple.1.id_for_label }}" class="w-label-3">{% trans perm_tuple.0.name %}</label></td>
<td>
{{ perm_tuple.1.tag }}
</td>

Wyświetl plik

@ -6,6 +6,7 @@ from django.contrib.auth import get_permission_codename
from django.contrib.auth.models import Permission
from django.contrib.contenttypes.models import ContentType
from django.utils.text import camel_case_to_spaces
from django.utils.translation import gettext_noop
from wagtail import hooks
from wagtail.admin.models import Admin
@ -55,6 +56,14 @@ def normalize_permission_label(permission: Permission):
return label
# normalize_permission_label will return "Can view" for Django's standard "Can view X" permission.
# formatted_permissions.html passes these labels through {% trans %} - since this is a variable
# within the template it will not be picked up by makemessages, so we define a translation here
# instead.
VIEW_PERMISSION_LABEL = gettext_noop("Can view")
@register.inclusion_tag("wagtailusers/groups/includes/formatted_permissions.html")
def format_permissions(permission_bound_field):
"""