-
Notifications
You must be signed in to change notification settings - Fork 87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow defining translatable_fields/override_translatable_fields on StructBlock #752
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #752 +/- ##
==========================================
+ Coverage 92.60% 92.65% +0.05%
==========================================
Files 46 47 +1
Lines 4017 4072 +55
Branches 598 603 +5
==========================================
+ Hits 3720 3773 +53
- Misses 175 176 +1
- Partials 122 123 +1 ☔ View full report in Codecov by Sentry. |
Thank you @freddiemixell. Could you please add some tests? |
No problem! I begin working on them already but alas the work week came and stole me away lol I will have some time starting this weekend and I'm off all next week so I will wrap this up then if I don't find during the week. |
@zerolab I figured out some intial tests. Let me know if you'd like more or any changes. Happy holidays! ☃️ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a solid start @freddiemixell
Can you update
wagtail-localize/docs/how-to/field-configuration.md
Lines 3 to 5 in 92c18ab
!!! attention | |
It is not currently possible to configure `StructBlock` translatable fields. See [Issue #307](https://github.com/wagtail/wagtail-localize/issues/307) for more details. |
Aside from that, I keep going back to the fact that for regular models we allow defining whether a field is translatable or is synchronised, and that we need to support this for StructBlock
s.
For example, in your CustomImageBlock
we want the description to be translatable, but the image to be synchronised. I am making an assumption here as I am not fully geared to test things locally ('tis Christmas after all), but what happens in that case?
Hey @zerolab, Thanks for checking this out on Christmas! (Tis Christmas made me lol) I see what you're saying about the image block and synchronization. I'll investigate if this will cause any issues with synchronized fields today. If you have any specific tests you're thinking of let me know and I'll try to hook it up, thanks again! |
I'll add that I'm not sure why exactly this is working with the images. That is what I'm going to work on figuring out now so I could really get behind this or find any flaws. |
Issue: When overriding the image of the youtube button in the french version with a picture of the Eiffel Tower I still see the Youtube button. I believe this means it's breaking the overridable segments somehow. Update: I reverted this change a second time, reset everything and now I do see the image block going through so this seems like a problem with this PR still. Whats actually happening:
This prevents the images from being overridden, which is sort of enforced by this configuration if you wanted to prevent images from being changed for some reason.
However, this configuration produces a different scenario where you can keep the same text but allow overriding the image. When I did this I was able to override the image successfully in the French version. Which means this isn't technically a bug but does allow for a little more control over nested images if you need it. |
|
||
## Specifying Translatable Fields within a StructBlock | ||
|
||
**By default, all sub-fields within a StructBlock are included for translation.** However, there may be instances where certain fields within the StructBlock should be excluded from translation. To facilitate this, we've introduced the **`translatable_blocks`** parameter. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick: no need to wrap inline code **
(bold)
|
||
## Specifying Translatable Fields within a StructBlock | ||
|
||
**By default, all sub-fields within a StructBlock are included for translation.** However, there may be instances where certain fields within the StructBlock should be excluded from translation. To facilitate this, we've introduced the **`translatable_blocks`** parameter. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: wrap StructBlock, CharBlock, TextBlock and YouTubeBlock in backticks (so they are treated as inline code)
|
||
##### Managing Images and Overrideable Segments within a StructBlock | ||
|
||
When dealing with overrideable segments such as images within a StructBlock, it's important to note that ignoring these segments could result in losing the ability to use a different image for different languages. If you want to maintain the ability to override an image, include it in the list of translatable_blocks to preserve the default behavior. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion:
When dealing with overrideable segments such as images within a StructBlock, it's important to note that ignoring these segments could result in losing the ability to use a different image for different languages. If you want to maintain the ability to override an image, include it in the list of translatable_blocks to preserve the default behavior. | |
It is important to note that ignoring overrideable segments such as images within a `StructBlock` could result in losing the ability to use a different image for different languages. If you want to maintain the ability to override an image, include it in the list of `translatable_blocks` to preserve the default behavior. |
translatable_blocks = ["caption", "image"] | ||
``` | ||
|
||
In this example, the image is still overrideable, but the address, which is unique to this location, is locked in by translatable_blocks. This allows you to maintain the flexibility of using different images for different languages, while ensuring that certain unique information remains consistent across all translations. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this example, the image is still overrideable, but the address, which is unique to this location, is locked in by translatable_blocks. This allows you to maintain the flexibility of using different images for different languages, while ensuring that certain unique information remains consistent across all translations. | |
In this example, the image is still overrideable. The address, nique to this location, is locked in by `translatable_blocks`. This allows you to maintain the flexibility of using different images for different languages, while ensuring that certain unique information remains consistent across all translations. |
@freddiemixell the code tests should pretty much follow what you test as a user, manually |
Hey @freddiemixell do you need any help / pointers on tests? |
Hi @zerolab! 👋 I'm Daniel from the Mozilla Foundation, on a team that heavily relies on Wagtail/wagtail-localize for our projects. We have a stakeholder request that would be directly fulfilled by the work in this PR. We noticed that your team had previously offered assistance with adding tests, but there hasn't been a response yet. We were wondering if there are any updates on this PR or an estimated timeline for when it might be merged. This information would help us set the right expectations with our own stakeholders. Additionally, if there's anything we can do to help move this forward, please let us know! Thanks 👍 |
Hey @danielfmiranda, It is a difficult one in that I had lots of non-localize work to attend to. If you/your team have the capacity, a PR that adds tests to this would move things quite a bit. Otherwise, I'll probably realistically get some time during Wagtail Space Netherlands which is mid-June. |
Is anyone working on those missing tests already? |
@Andreew4x4 unfortunately, it doesn't look like it. |
This PR is attempting to allow users to mark certain sub-blocks of a struct block to be ignored like UrlBlock.
Example use case:
blocks.py
In the above example the first block doesn't define the property so it goes through the code the same as before.
The second block only includes the description field, which technically doesn't matter because the image would be skipped regardless. However, I added it in to illustrate how you could exclude fields by simply not adding them to the list.
The last 2 examples we add the property but with an empty list. That will prevent any blocks from this struct block from being extracted.
Notes:
Closes #307