Skip to content

Add tests and documentation updates for StructBlock translatable_blocks support (based on #752)#882

Open
Andreew4x4 wants to merge 8 commits intowagtail:mainfrom
Andreew4x4:tests
Open

Add tests and documentation updates for StructBlock translatable_blocks support (based on #752)#882
Andreew4x4 wants to merge 8 commits intowagtail:mainfrom
Andreew4x4:tests

Conversation

@Andreew4x4
Copy link
Copy Markdown

@Andreew4x4 Andreew4x4 commented Oct 17, 2025

This PR adding comprehensive tests and documentation improvements for the already-implemented translatable_blocks feature on the open #752, which addresses issue #307.
The feature allows developers to control which sub-fields of a StructBlock are translatable by defining a translatable_blocks attribute on the block class.
The core implementation changes were introduced in the cherry-picked commits (6835d9d, 417b8de, 91ad754, 0205300) from the @freddiemixell's fork.

The tests ensure the feature works as designed and the documentation provides clear guidance for developers on how to use translatable_blocks to control which StructBlock sub-fields are translatable, addressing the long-standing request in issue #307.

Closes #752.
CC: @freddiemixell (?) @zerolab for review. Appreciate any feedback!

- Remove override_translatable_blocks section from field-configuration.md
- Update test docstring to reflect actual implementation
- Feature was documented but not implemented in extract.py

The override_translatable_blocks feature was documented in the how-to
guide but is not actually implemented in the extraction code. Removing
this section to avoid user confusion until the feature is fully
implemented.

This change ensures documentation accurately describes only the
implemented translatable_blocks feature.
- Extract segments from synchronized StreamFields (was returning 0 segments)
- CharBlock/TextBlock return OverridableSegmentValue in synchronized fields
- Add is_synchronized_field parameter to distinguish explicit SynchronizedField
- Fix test attribute: s.data -> s.string
Copy link
Copy Markdown

@sushanthaaa sushanthaaa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Andreew4x4 ,I reviewed the PR and tested the implementation locally.
Here's my review:
This looks solid. The core implementation is clean and backward compatible, the tests are comprehensive, and the documentation is thorough with practical examples. I appreciate the variety of test scenarios (YouTubeBlock, CodeBlock, AddressBlock) as they make it easy to understand the use cases.

A few observations:

  1. Silent failure on typos: If a developer misspells a field name in translatable_blocks (e.g., ["decription"] instead of ["description"]), the field is silently excluded. Would it be worth logging a warning when a field name in translatable_blocks doesn't match any child block? This could save debugging time.

  2. Interaction with get_translatable_segments(): I noticed that if a StructBlock defines both translatable_blocks and get_translatable_segments(), the latter takes priority since it's checked before the StructBlock handler is reached. It might be helpful to add a note about this in the documentation, so developers know which one "wins."

  3. Nested translatable_blocks test: The nested StructBlock test (test_nested_structblock_with_translatable_blocks) tests a StreamBlock nested inside a page, but it doesn't test a StructBlock-inside-StructBlock where both levels have different translatable_blocks. Would that be a useful additional test case?

These are minor observations. the PR looks good to merge as-is. Great work completing the long-standing request from issue #307!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants