wagtail / wagtail-localize

Translation plugin for Wagtail CMS
https://wagtail-localize.org/
Other
226 stars 86 forks source link

Orderables are not translatable? #680

Closed unreadableusername closed 1 year ago

unreadableusername commented 1 year ago

The issue

When binding a custom model to a page with the Orderable recipe, it is not translatable.

I created a repository with demonstration code for easy reproduction here: GitHub Repo If more or detailed information is needed just let me know - happy to help :)

Demonstration project

The example project contains a app_custom_models app that implements one snippet for a ContactPerson

The default Wagtail home app has been modified to hold orderables. page_de

The editing interface of the home page edit_german_page

When switching to the English editing interface, the orderables are not shown for translation: edit_english_page

Expected behavior

Expected behavior is for the orderables to show as translatable along with their segments, like its the case for translating snippets in a FieldPanel which embedds a single snippet into a page wagtail-localize documentation Screenshot 2023-03-06 150521

zerolab commented 1 year ago

wagtail-localize tries to auto-detect the various fields as described in https://www.wagtail-localize.org/concept/translatable-fields-autogen/. A key inclusion factor is that the model needs to inherit from TranslatableMixin

This looks similar to https://github.com/wagtail/wagtail-localize/blob/main/wagtail_localize/test/models.py#L402. Except your ContactPersonOrderable is not inheriting from TranslatableMixin.

If even after updating the inheritance pattern it doesn't pick up things properly, try setting the translatable_fields attribute?

e.g. https://github.com/unreadableusername/wagtail-localize-orderables/blob/main/home/models.py#L7-L9 to become

class ContactPersonOrderable(TranslatableMixin, Orderable):
    page = ParentalKey('home.HomePage', on_delete=models.CASCADE, related_name='contact_persons')
    person = models.ForeignKey('app_custom_models.ContactPerson', on_delete=models.CASCADE, related_name='+')

    translatable_fields = [TranslatableField("person")]

and potentially

# ...

class HomePage(Page):
    # ...
    translatable_fields = [TranslatableField("contact_persons")]
unreadableusername commented 1 year ago

Thank you for your time :) It worked flawlessly with the addition that I had to use the BootstrapTranslatableMixin to account for my existing database entries. - That's on me for wanting to keep them.

Your explanation helped a ton, and I am very grateful for your work here!