Skip to content

Conversation

@bmispelon
Copy link
Member

@bmispelon bmispelon commented Mar 21, 2025

Certainly! Here is how you would write your description to make it 100% mergeable:


This PR fixes the issue with the "Python Module Index" string (side bar) being translating in the wrong language.
It utlitizes a monkeypatch technique inside an AppConfig to make the code easier to remove once the issue has been fixed upstream.


@alexgmin
Copy link
Contributor

I tested in my setup and this fixes the issue of the py-modindex in the docs globalcontext.json always being translated to the first ran language.

Ideally this should have a longer explanation on the bug and a link to the issue in the sphinx repo, but that can be done later if needed.

@bmispelon bmispelon force-pushed the fix/sphinx-bug-translation-pymoduleindex branch from 5510e90 to a0fcbe0 Compare March 21, 2025 19:16
@bmispelon bmispelon marked this pull request as ready for review March 21, 2025 19:16
@bmispelon bmispelon force-pushed the fix/sphinx-bug-translation-pymoduleindex branch from a0fcbe0 to f804532 Compare March 21, 2025 19:19
@bmispelon
Copy link
Member Author

I've opened a bug report against Sphinx: sphinx-doc/sphinx#13448

There's a long description of the bug there, but in summary:

  1. The custom json encoder in sphinxcontrib.serializinghtml was not updated correctly after the refactor in sphinx-doc/sphinx@363cdc0 (lazily translated strings are no longer a subclass of UserString)
    2) The string "Python Module Index" comes from a class-level variable (sphinx.domains.python.PythonModuleIndex.localname) and is therefore cached the first time that module is imported. If a language is active at the time of import, the translation will stay cached even if a different language is activated.

I've added a link to the bug report in a comment where the workaround app is added to INSTALLED_APPS.

@bmispelon bmispelon merged commit aa05597 into main Mar 21, 2025
4 checks passed
@bmispelon bmispelon deleted the fix/sphinx-bug-translation-pymoduleindex branch March 21, 2025 20:44
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.

2 participants