@@ -202,17 +202,24 @@ def _images_path_to_static(uri: str) -> str:
202202 return uri
203203
204204
205- def _rewrite_locale_asset_paths (doctree : nodes .document ) -> None :
205+ def _rewrite_locale_asset_paths (doctree : nodes .document , language : str = "en" ) -> None :
206206 """Rewrite image paths so they work on ReadTheDocs for both en and es builds.
207207
208208 Use _static/ for doc images (copied via html_static_path) so paths work regardless
209209 of URL depth (/es/latest/, /en/latest/, etc.).
210+ For Spanish (es), replace en_documentation with es_documentation so locale-specific
211+ images are used.
210212 """
213+ use_es_images = language == "es"
211214 for node in doctree .traverse (nodes .image ):
212215 uri = node .get ('uri' , '' )
216+ if use_es_images and 'en_documentation' in uri :
217+ uri = uri .replace ('en_documentation' , 'es_documentation' )
213218 new_uri = _images_path_to_static (uri )
214- if new_uri != uri :
219+ if new_uri != node . get ( ' uri' , '' ) :
215220 node ['uri' ] = new_uri
221+ if 'candidates' in node :
222+ node ['candidates' ] = {'*' : node ['uri' ]}
216223
217224
218225# Regex for paragraphs that are only markdown image or link (locale builds sometimes
@@ -405,7 +412,8 @@ def _convert_literal_markdown_paragraphs(app, doctree: nodes.document, docname:
405412def _rewrite_doc_md_links (app , doctree , docname ):
406413 """Rewrite links to docs/*.md so they point to the built .html (works in both .md and Sphinx)."""
407414 # Fix image paths for locale builds (content from .po resolves paths from source/)
408- _rewrite_locale_asset_paths (doctree )
415+ language = getattr (app .config , 'language' , 'en' )
416+ _rewrite_locale_asset_paths (doctree , language )
409417 # Convert paragraphs that are literal markdown image/link (gettext can emit raw text)
410418 _convert_literal_markdown_paragraphs (app , doctree , docname )
411419
0 commit comments