Skip to content

fix: don't let translated snippets clobber a page's sphinx metadata - #1231

Open
rahul05ranjan wants to merge 2 commits into
executablebooks:masterfrom
rahul05ranjan:fix/translated-snippet-metadata
Open

rahul05ranjan wants to merge 2 commits into
executablebooks:masterfrom
rahul05ranjan:fix/translated-snippet-metadata

Conversation

@rahul05ranjan

Copy link
Copy Markdown

Fixes #844

What's wrong

Since Sphinx parses each translated message with a throwaway document (whose source ends in :<translated>), any snippet that MyST renders with headings lets _render_finalise() overwrite the page's own env.metadata[docname] entries:

Reproduced on master (5137add, Sphinx 9.2.0), with the exact repro from #844:

$ sphinx-build -b html -D language=es . _build/es
index.md:7: WARNING: local id not found in doc 'other': 'beta' [myst.xref_missing]
build succeeded, 1 warning.

(no warning at all with -D language=en)

Fix

Skip both env.metadata writes in _render_finalise() when the document being rendered is a translation snippet, i.e. its document["source"] ends with :<translated> (the marker Sphinx's _publish_msgstr sets). The snippet document's own attributes (document.myst_slugs, the wordcount-* substitutions) are unchanged — only the write into the shared env.metadata is suppressed.

Tests

New test_translated_local_id (new translated_slugs sourcedir: a fr translation of an admonition title, so the translated snippet is a heading; an other.md#beta link):

  • fails on un-fixed master with exactly WARNING: local id not found in doc 'other': 'beta' [myst.xref_missing],
  • passes with this fix, and asserts other.html#beta is still the emitted href (the link itself never broke — only the resolution did),
  • pytest tests/test_sphinx: 28 passed + the 2 test_extended_syntaxes failures that fail identically on a clean master checkout (sphinx-version fixture drift on this host),
  • pytest --ignore=tests/test_sphinx: 1535 passed, 12 skipped, plus the 1 pre-existing test_cmdline[40-linkify] docutils-version fixture failure, identical to a clean checkout (sphinx 9.2.0 / docutils 0.23 / Python 3.13).

Note: the .po fixture is enough for CI — sphinx auto-compiles outdated catalogs at build time (compile_all_catalogs).

rahul05ranjan and others added 2 commits November 13, 2026 07:49
Sphinx's Locale transform parses each translated message with a new
document whose source ends in ':<translated>'. When the snippet is a
heading (Sphinx appends an '===' underline to translated titles),
_render_finalise then overwrote env.metadata[docname]["myst_slugs"]
with the snippet's own slugs, so local anchors like other.md#beta
stopped resolving in translated builds (a suppressible
myst.xref_missing warning per link, executablebooks#844). The always-on wordcount
metadata write had the same clobber and is guarded the same way.

Skip both env.metadata writes when the document is a translation
snippet; the snippet document's own attributes are unaffected.

Fixes executablebooks#844

Co-authored-by: rahul05ranjan <11793455+rahul05ranjan@users.noreply.github.com>

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Warning "local id not found in doc" in translated docs since MyST-parser 0.19.0

1 participant