I am new to wagtail and i am working with a custom menu. I set up a custom menu class and use a tag to display the menu-items in the templates. This works fine, however i would need to create different menus depending on what language my site is used in. (i know wagtailmenus exists, however i could not find a satisfying way to create translated menus there either)
I wanted to create a similar translation experience like wagtail-localize does with pages. Is this possible or do i have to take a different approach?
I already tried to use wagtails TranslatableMixin to simply create duplicates of my menu with different translations, however this does not seem to work, because the translate option (like it is done with pages) is missing.
Classes:
class Menu(TranslatableMixin, ClusterableModel):
title = models.CharField(max_length=100)
logo = models.ForeignKey("wagtailimages.Image", blank=True, null=True, on_delete=models.SET_NULL, related_name="menu_logo")
image = models.ForeignKey("wagtailimages.Image", blank=True, null=True, on_delete=models.SET_NULL, related_name="menu_image")
slug = AutoSlugField(populate_from="title", editable=True)
panels = [
MultiFieldPanel(
[
FieldPanel("title"),
FieldPanel("slug"),
ImageChooserPanel("logo"),
ImageChooserPanel("image"),
],
heading="Menu",
),
InlinePanel("menu_items", label="Menu Item"),
]
def __str__(self):
return self.title
class Meta(TranslatableMixin.Meta):
verbose_name = "Menu"
class MenuItem(ClusterableModel, AbstractMenuItem):
page = ParentalKey("Menu", related_name="menu_items")
class Meta:
verbose_name = "Menu Item"
Templatetags:
@register.simple_tag()
def get_menu(slug, authencicated):
menu = Menu.objects.get(slug=slug)
all_menu_items = menu.menu_items.all()
menu_items = []
for item in all_menu_items:
if item.show(authencicated):
menu_items.append(item)
return {"logo": menu.logo, "image": menu.image, "items": menu_items}
template:
{% get_menu "main-menu" request.user.is_authenticated as menu%}