You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I publish a new default language (norwegian) ProductPage choosing a couple of materials
I translate to english using wagtail-localize. The materials field is hidden from the UI (auto-sync behaviour)
I inspect the new page's materials (instances of ProductPageMaterial) via shell
I see that a new ProductPageMaterial has been created by wagtail/wagtail-localize. It's page foreign key field is pointing the new english version of the page as expected. The material foreign key field, however, is still pointing to a norweigan material.
I would expect to see the local (english) material in the same way I see the local page.
I have made this temporary workaround but don't image it will be relevant for any long term solution:
classInlineModelTranslationHelper:
page: Pagetarget_field_name: strdefsave(self, *args, **kwargs) ->None:
# Force the target field locale to match the locale of the page.# This is because wagtail localize seems to translate the page foreign key# but leaves the other foreign key in the original language.target_obj: TranslatableMixin=getattr(self, self.target_field_name)
ifnotself.page.locale==target_obj.locale:
logger.info(
f"Page {self.target_field_name} '{target_obj}' has locale "f"{target_obj.locale} but page has locale {self.page.locale}"
)
iflocal_obj:=target_obj.get_translation_or_none(locale=self.page.locale):
logger.info(f"... using an existing translation of {target_obj}.")
else:
logger.info(
f"... no existing translation for {target_obj} "f"with locale {self.page.locale} so creating a new one."
)
# This will crash if the targer object is a page whose parent has not yet been translated.local_obj=target_obj.copy_for_translation(locale=self.page.locale)
local_obj.save()
setattr(self, self.target_field_name, local_obj)
returnsuper().save(*args, **kwargs)
The text was updated successfully, but these errors were encountered:
The key doesn't get translated and will always point to the key in the locale the page was created in. You should be able to get the translated child object by localising it.
Creating issue after posting to slack #multi-language and discussing with @zerolab
I have a translatable snippet which I add to a page model via an inline model:
What happens:
I see that a new ProductPageMaterial has been created by wagtail/wagtail-localize. It's page foreign key field is pointing the new english version of the page as expected. The material foreign key field, however, is still pointing to a norweigan material.
I would expect to see the local (english) material in the same way I see the local page.
I have made this temporary workaround but don't image it will be relevant for any long term solution:
The text was updated successfully, but these errors were encountered: