wagtail 中的 Slug 翻译问题

Slug translation issue in wagtail

我整天都在网上阅读有关以下问题的信息,如果我注册以下模型进行翻译,则在 wagtail 中:

class RecipientsPage(Page):
intro = RichTextField(null=True, blank=True)
banner_image = models.ForeignKey(
    "wagtailimages.Image",
    on_delete=models.SET_NULL,
    related_name="+",
    null=True,
    blank=False,
    help_text=_("the Image shouldn't exceed ") + "1350 * 210",
)
content_panels = Page.content_panels + [
    FieldPanel("intro"),
    ImageChooserPanel("image"),
]

这是我注册模型的方式:

@register(RecipientsCountriesPage)
class RecipientsCountriesPage(TranslationOptions):
fields = ("intro",)

这会导致问题,因为像这样我会在两个标题后面有两个 slug(原始英文和阿拉伯语翻译的),如果我手动将阿拉伯语 slug 更改为与英文相同,它会工作,但手动为每个页面这样做效率不高 我在这里读了很多关于这个问题的文章: https://github.com/infoportugal/wagtail-modeltranslation/issues/195 我还发现以下问题没有答案 How do you translate the slug value of a page? 我还读到我可以覆盖一些 wagtail Page 方法,但没有进一步的解释,我有点迷茫,解决这个问题的最好方法是什么?

我是用 Django 信号做的

@receiver(pre_save)
def set_arabic_slug_on_new_instance(sender, instance, **kwargs):
    if isinstance(instance, Page):
        instance.slug_ar = instance.slug_en