Skip to content

Commit d7e6eee

Browse files
committed
Sphinx corrected for spanish
1 parent af88ecb commit d7e6eee

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

sphinx-docs/source/conf.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,27 @@ def _get_fragment(raw: str) -> str:
188188
_DOC_HTML_TO_DOCNAME = {v: v.replace('.html', '') for v in _DOC_MD_TO_HTML.values()}
189189

190190

191+
def _rewrite_locale_asset_paths(doctree: nodes.document) -> None:
192+
"""Rewrite image paths so they work in both normal and gettext (locale) builds.
193+
194+
In locale builds, content comes from .po files; relative paths like ../images/...
195+
are then resolved from the document dir (source/), so ../images points to
196+
sphinx-docs/images instead of project root. Fix by rewriting ../images/ to
197+
../../images/ (relative to source/ = project root images/).
198+
"""
199+
prefix = '../images/'
200+
replacement = '../../images/'
201+
for node in doctree.traverse(nodes.image):
202+
uri = node.get('uri', '')
203+
if uri.startswith(prefix):
204+
node['uri'] = replacement + uri[len(prefix):]
205+
206+
191207
def _rewrite_doc_md_links(app, doctree, docname):
192208
"""Rewrite links to docs/*.md so they point to the built .html (works in both .md and Sphinx)."""
209+
# Fix image paths for locale builds (content from .po resolves paths from source/)
210+
_rewrite_locale_asset_paths(doctree)
211+
193212
builder = getattr(app, 'builder', None)
194213
get_uri = getattr(builder, 'get_relative_uri', None) if builder else None
195214

0 commit comments

Comments
 (0)