Wagtail 2.12 translations problem with wagtail_localize and StreamField

259 Views Asked by At

I am using wagtail built-in translations system with wagtail_localize. For StreamFields with nested content, only external content is available for translation.

Look at this example:

class Carousel(blocks.StructBlock):
  title = blocks.CharBlock(label='Titolo')
  text = blocks.RichTextBlock(label='Testo')
  items = blocks.ListBlock(blocks.StructBlock([
            ('tab_label', blocks.CharBlock(label='Testo visualizzato sulla tab')),
            ('title', blocks.CharBlock(label='Titolo')),
            ('text', blocks.RichTextBlock(label='Testo')),
            ('photo', ImageChooserBlock(label='Foto')),
            ('page', QuickPageLinkBlock(required=False)),
            ('color', NativeColorBlock(default="#085083", label = 'Colore per il titolo')),
        ]), label = 'Lista slide')
  
  class Meta:
    icon='snippet'
    label = 'Carosello'
    template = 'blocks/carousel.html'

Only title and text are available for translations, but not all the items. enter image description here I also need to translate items. How can i solve?

Moreover it seems that linked pages contained in snippets (in pages it works) cannot be translated, but I need to change the link to the correct language page.

Can someone help me? Thanks, Sabrina

1

There are 1 best solutions below

0
Arian On

I recommend using a StreamBlock instead of ListBlock for items. The content of StreamBlock is translatable. I don't think ListBlocks can be translated yet (see here)

# Do not do this:
items = blocks.ListBlock(blocks.StructBlock(...))

# Do this instead:
items = blocks.StreamBlock([('item', blocks.StructBlock(...))])