diff --git a/wagtail_localize/segments/tests/test_segment_extraction.py b/wagtail_localize/segments/tests/test_segment_extraction.py index c19a068bb..087b38940 100644 --- a/wagtail_localize/segments/tests/test_segment_extraction.py +++ b/wagtail_localize/segments/tests/test_segment_extraction.py @@ -533,6 +533,40 @@ def test_customstructblock(self): ], ) + def test_structblockwithoverrides(self): + block_id = uuid.uuid4() + page = make_test_page_with_streamfield_block( + str(block_id), + "test_structblockwithoverrides", + {"field_a": "Test content", "field_b": "Non-translatable content"}, + ) + + segments = extract_segments(page) + + self.assertEqual( + segments, + [ + StringSegmentValue( + f"test_streamfield.{block_id}.field_a", + "Test content", + ) + ], + ) + + def test_structblockignoreall(self): + block_id = uuid.uuid4() + page = make_test_page_with_streamfield_block( + str(block_id), + "test_structblockignoreall", + { + "field_a": "Non-translatable content", + "field_b": "Non-translatable content", + }, + ) + + segments = extract_segments(page) + self.assertEqual(segments, []) + def test_customblockwithoutextractmethod(self): block_id = uuid.uuid4() page = make_test_page_with_streamfield_block( diff --git a/wagtail_localize/test/models.py b/wagtail_localize/test/models.py index 4ff6fc9d8..83b4ee870 100644 --- a/wagtail_localize/test/models.py +++ b/wagtail_localize/test/models.py @@ -119,6 +119,20 @@ class TestNestedStreamBlock(blocks.StreamBlock): chooser_in_list = blocks.ListBlock(blocks.PageChooserBlock()) +class TestStructBlockOverride(blocks.StructBlock): + field_a = blocks.TextBlock() + field_b = blocks.TextBlock() + + override_translatable_blocks = ["field_a"] + + +class TestStructBlockIgnoreAll(blocks.StructBlock): + field_a = blocks.TextBlock() + field_b = blocks.TextBlock() + + override_translatable_blocks = [] + + class TestNestedChooserStructBlock(blocks.StructBlock): nested_page = TestChooserStructBlock() @@ -196,6 +210,8 @@ class TestStreamBlock(blocks.StreamBlock): test_nestedstreamblock = TestNestedStreamBlock() test_streamblock_in_structblock = TestStreamBlockInStructBlock() test_customstructblock = CustomStructBlock() + test_structblockwithoverrides = TestStructBlockOverride() + test_structblockignoreall = TestStructBlockIgnoreAll() test_customblockwithoutextractmethod = CustomBlockWithoutExtractMethod() test_pagechooserblock = blocks.PageChooserBlock() test_pagechooserblock_with_restricted_types = blocks.PageChooserBlock(