Skip to content

Gettext builder not extracting content of doctest blocks #12871

Description

@m-aciek

Describe the bug

Hi, running a gettext builder on a documents with doctest-block in gettext_additional_targets doesn't add the content of doctest blocks in generated POTs.

How to Reproduce

  1. Add doctest-block to gettext_additional_targets in conf.py
    (gh-123407: Allow translation of doctest blocks content python/cpython#123852).

  2. Run % make gettext.

  3. -> lack of expected doctest blocks in POTs, example one: https://github.com/python/cpython/blob/be90648fb2de58b148dcc7553a08ca646911baf2/Doc/tutorial/introduction.rst?plain=1#L150-L155

Environment Information

Sphinx version: v7.3.7

Additional context

From a quick look I'm not able to figure out the cause in the Sphinx codebase.

Activity

  1. jdillard commented on Aug 22, 2026

    @jdillard
    SponsorMember

    A minimal comparison with gettext_additional_targets = ['doctest-block'] gives the same result on Sphinx 7.3.7 and current main:

    >>> 2 + 2
    4

    is extracted, while:

       >>> 2 + 2
       4

    is missing from the POT file.

    The likely cause is source metadata. After transforms, both nodes have translatable=True and the same rawsource, but the indented doctest has source=None; sphinx.util.nodes.is_translatable() therefore skips it. apply_source_workaround() repairs this case for nested literal_block nodes, but not for doctest_block nodes.

    The fix should add nodes.doctest_block to that source workaround and add regression coverage using an indented doctest matching the CPython example.

    edit: The source-metadata cause has since been confirmed in feature request #41, and the Sphinx workaround is proposed in #14632.

  2. added
    awaiting:reviewPR waiting for a review by a maintainer.
    docutilsTags upstream Docutils issues
    on Aug 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions