infoportugal / wagtail-modeltranslation

Simple app to patch modeltranslation (https://github.com/deschler/django-modeltranslation) into Wagtail CMS.
151 stars 119 forks source link

Is there a way to add i18n to a CustomImage model? #403

Closed andreasnuesslein closed 7 months ago

andreasnuesslein commented 1 year ago

For a client, I need to add captions and comments to an image. These fields (caption and comment) need to be available in different languages.

For the custom image I started to use this: https://docs.wagtail.org/en/stable/advanced_topics/images/custom_image_model.html but I am not getting i18n fields for the image in the wagtail CMS backend

I'm guessing this was so far not really a thing? Or am I mistaken? Anyways: any pointers would be appreciated :)

Thanks

DiogoMarques29 commented 7 months ago

Hey @andreasnuesslein,

I'm afraid it might not be feasible because we haven't implemented patching for the admin module regarding images. However, there's an alternative route you could take. You can register the foreign key associated with your custom images for translation. This will enable you to utilize an image picker across all supported languages seamlessly.

andreasnuesslein commented 7 months ago

Hola Diogo, thank you for your response! I'm afraid I don't exactly understand. Could you give me a brief example?

Do you mean like: have a one-to-one relation to the image model that has the relevant custom fields? But how would I get the imag picker then? Maybe I've got a knot in my brain.

Thanks again :)

DiogoMarques29 commented 7 months ago

You may add a ForignKey to your custom image model like this: image = models.ForeignKey( 'yourapp.yourcustomimage', on_delete=models.PROTECT, related_name='+', verbose_name=_('Image') )

and than register that field for translation.

Hope thats a bit clear now!

Cheers

andreasnuesslein commented 7 months ago

ah that's what you mean. not sure that would work well with the built-in wagtail image library? (i.e. WAGTAILIMAGES_IMAGE_MODEL = 'images.CustomImage' )

I used a different solution now altogether but thanks for your help!