Repository navigation
fix: don't let translated snippets clobber a page's sphinx metadata - #1231
Open
rahul05ranjan wants to merge 2 commits into
Open
rahul05ranjan wants to merge 2 commits into
rahul05ranjan wants to merge 2 commits into
Conversation
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>
for more information, see https://pre-commit.ci
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 ownenv.metadata[docname]entries:myst_slugsgets replaced by the snippet's slugs, so local anchors like[beta](other.md#beta)stop resolving in translated builds and emit one suppressiblemyst.xref_missingwarning per link (reported by @jpmckinney with a minimal repro in Warning "local id not found in doc" in translated docs since MyST-parser 0.19.0 #844);wordcount(the wordcount plugin is always on) gets replaced by the snippet's count.Reproduced on master (
5137add, Sphinx 9.2.0), with the exact repro from #844:(no warning at all with
-D language=en)Fix
Skip both
env.metadatawrites in_render_finalise()when the document being rendered is a translation snippet, i.e. itsdocument["source"]ends with:<translated>(the marker Sphinx's_publish_msgstrsets). The snippet document's own attributes (document.myst_slugs, thewordcount-*substitutions) are unchanged — only the write into the sharedenv.metadatais suppressed.Tests
New
test_translated_local_id(newtranslated_slugssourcedir: afrtranslation of an admonition title, so the translated snippet is a heading; another.md#betalink):WARNING: local id not found in doc 'other': 'beta' [myst.xref_missing],other.html#betais still the emitted href (the link itself never broke — only the resolution did),pytest tests/test_sphinx: 28 passed + the 2test_extended_syntaxesfailures 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-existingtest_cmdline[40-linkify]docutils-version fixture failure, identical to a clean checkout (sphinx 9.2.0 / docutils 0.23 / Python 3.13).Note: the
.pofixture is enough for CI — sphinx auto-compiles outdated catalogs at build time (compile_all_catalogs).