Use gettext_lazy instead of gettext in rich-text editor

pull/12910/head
Bernhard Bliem 2023-10-17 18:30:15 +02:00 zatwierdzone przez Thibaud Colas
rodzic 7c284d9e31
commit 3f381892cd
5 zmienionych plików z 35 dodań i 22 usunięć

Wyświetl plik

@ -4,6 +4,7 @@ from django.conf import settings
from django.test import SimpleTestCase, TestCase
from django.test.utils import override_settings
from django.urls import reverse, reverse_lazy
from django.utils import translation
from wagtail.admin.rich_text import DraftailRichTextArea, get_rich_text_editor_widget
from wagtail.admin.rich_text.converters.editor_html import (
@ -636,3 +637,16 @@ class TestRichTextChooserUrls(WagtailTestUtils, BaseRichTextEditHandlerTestCase)
self.assertIn("/admin/images/chooser/", html)
self.assertIn("/admin/embeds/chooser/", html)
self.assertIn("/admin/documents/chooser/", html)
class TestDraftailLazyTranslations(SimpleTestCase):
def test_context_i18n(self):
widget = DraftailRichTextArea(features=["h2"])
context_default_language = widget.get_context(None, None, {})
with translation.override("de"):
context_de = widget.get_context(None, None, {})
# At least the description of the h2 feature should be different
self.assertNotEqual(
context_default_language["widget"]["attrs"]["data-w-init-detail-value"],
context_de["widget"]["attrs"]["data-w-init-detail-value"],
)

Wyświetl plik

@ -3,7 +3,6 @@ from django.contrib.auth.models import Permission
from django.urls import reverse, reverse_lazy
from django.utils.functional import cached_property
from django.utils.http import urlencode
from django.utils.translation import gettext
from django.utils.translation import gettext_lazy as _
from draftjs_exporter.dom import DOM
@ -495,7 +494,7 @@ def register_core_features(features):
{
"icon": "h1",
"type": "header-one",
"description": gettext("Heading %(level)d") % {"level": 1},
"description": _("Heading 1"),
}
),
)
@ -516,7 +515,7 @@ def register_core_features(features):
{
"icon": "h2",
"type": "header-two",
"description": gettext("Heading %(level)d") % {"level": 2},
"description": _("Heading 2"),
}
),
)
@ -537,7 +536,7 @@ def register_core_features(features):
{
"icon": "h3",
"type": "header-three",
"description": gettext("Heading %(level)d") % {"level": 3},
"description": _("Heading 3"),
}
),
)
@ -558,7 +557,7 @@ def register_core_features(features):
{
"icon": "h4",
"type": "header-four",
"description": gettext("Heading %(level)d") % {"level": 4},
"description": _("Heading 4"),
}
),
)
@ -579,7 +578,7 @@ def register_core_features(features):
{
"icon": "h5",
"type": "header-five",
"description": gettext("Heading %(level)d") % {"level": 5},
"description": _("Heading 5"),
}
),
)
@ -600,7 +599,7 @@ def register_core_features(features):
{
"icon": "h6",
"type": "header-six",
"description": gettext("Heading %(level)d") % {"level": 6},
"description": _("Heading 6"),
}
),
)
@ -621,7 +620,7 @@ def register_core_features(features):
{
"type": "unordered-list-item",
"icon": "list-ul",
"description": gettext("Bulleted list"),
"description": _("Bulleted list"),
}
),
)
@ -645,7 +644,7 @@ def register_core_features(features):
{
"type": "ordered-list-item",
"icon": "list-ol",
"description": gettext("Numbered list"),
"description": _("Numbered list"),
}
),
)
@ -669,7 +668,7 @@ def register_core_features(features):
{
"type": "blockquote",
"icon": "openquote",
"description": gettext("Blockquote"),
"description": _("Blockquote"),
}
),
)
@ -691,7 +690,7 @@ def register_core_features(features):
{
"type": "BOLD",
"icon": "bold",
"description": gettext("Bold"),
"description": _("Bold"),
}
),
)
@ -713,7 +712,7 @@ def register_core_features(features):
{
"type": "ITALIC",
"icon": "italic",
"description": gettext("Italic"),
"description": _("Italic"),
}
),
)
@ -736,7 +735,7 @@ def register_core_features(features):
{
"type": "LINK",
"icon": "link",
"description": gettext("Link"),
"description": _("Link"),
# We want to enforce constraints on which links can be pasted into rich text.
# Keep only the attributes Wagtail needs.
"attributes": ["url", "id", "parentId"],
@ -783,7 +782,7 @@ def register_core_features(features):
{
"type": "SUPERSCRIPT",
"icon": "superscript",
"description": gettext("Superscript"),
"description": _("Superscript"),
}
),
)
@ -804,7 +803,7 @@ def register_core_features(features):
{
"type": "SUBSCRIPT",
"icon": "subscript",
"description": gettext("Subscript"),
"description": _("Subscript"),
}
),
)
@ -825,7 +824,7 @@ def register_core_features(features):
{
"type": "STRIKETHROUGH",
"icon": "strikethrough",
"description": gettext("Strikethrough"),
"description": _("Strikethrough"),
}
),
)
@ -846,7 +845,7 @@ def register_core_features(features):
{
"type": "CODE",
"icon": "code",
"description": gettext("Code"),
"description": _("Code"),
}
),
)

Wyświetl plik

@ -4,8 +4,8 @@ from django.conf import settings
from django.template.response import TemplateResponse
from django.urls import include, path, reverse, reverse_lazy
from django.utils.cache import add_never_cache_headers
from django.utils.translation import gettext, ngettext
from django.utils.translation import gettext_lazy as _
from django.utils.translation import ngettext
import wagtail.admin.rich_text.editors.draftail.features as draftail_features
from wagtail import hooks
@ -78,7 +78,7 @@ def register_document_feature(features):
{
"type": "DOCUMENT",
"icon": "doc-full-inverse",
"description": gettext("Document"),
"description": _("Document"),
"chooserUrls": {
"documentChooser": reverse_lazy("wagtaildocs_chooser:choose")
},

Wyświetl plik

@ -1,5 +1,5 @@
from django.urls import include, path, reverse_lazy
from django.utils.translation import gettext as _
from django.utils.translation import gettext_lazy as _
import wagtail.admin.rich_text.editors.draftail.features as draftail_features
from wagtail import hooks

Wyświetl plik

@ -1,6 +1,6 @@
from django.urls import include, path, reverse, reverse_lazy
from django.utils.translation import gettext, ngettext
from django.utils.translation import gettext_lazy as _
from django.utils.translation import ngettext
import wagtail.admin.rich_text.editors.draftail.features as draftail_features
from wagtail import hooks
@ -76,7 +76,7 @@ def register_image_feature(features):
{
"type": "IMAGE",
"icon": "image",
"description": gettext("Image"),
"description": _("Image"),
# We do not want users to be able to copy-paste hotlinked images into rich text.
# Keep only the attributes Wagtail needs.
"attributes": ["id", "src", "alt", "format"],