Skip to content

Fix copy button translations using template labels - #337

Draft
m-aciek wants to merge 1 commit into
python:mainfrom
m-aciek:fix-copy-button-translations
Draft

m-aciek wants to merge 1 commit into
python:mainfrom
m-aciek:fix-copy-button-translations

Conversation

@m-aciek

@m-aciek m-aciek commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

The Babel runner doesn't generate JavaScript translation catalogs. Rather than adding that step, move the labels to layout.html so they can use the existing theme translation machinery.

Also remove JavaScript extraction from .babel.cfg, since the theme's JavaScript files no longer contain translatable strings.

@m-aciek
m-aciek requested a review from tomasr8 November 21, 2026 20:34
@read-the-docs-community

Copy link
Copy Markdown

Documentation build overview

📚 python-docs-theme-previews | 🛠️ Build #36070692 | 📁 Comparing 154f1c8 against latest (db635c1)

  🔍 Preview build  

137 files changed · + 1 added · ± 136 modified

+ Added

± Modified

@tomasr8

tomasr8 commented Nov 21, 2026

Copy link
Copy Markdown
Member

The Babel runner doesn't generate JavaScript translation catalogs.

Why is that? If it's not too complicated I'd prefer to fix the extraction so that we can avoid the data attribute indirection and also have other JS strings added in the future work as well.

@StanFromIreland

StanFromIreland commented Nov 21, 2026 •

Copy link
Copy Markdown
Member

I've tried it before and IIUC Sphinx has no native support so this is unfeasible without convoluted hacks.

@m-aciek

m-aciek commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor Author

I've opened an alternative draft pull request: #338. I initially thought adding support for generating JavaScript translation catalogs was a bit much for just three strings, but I don't feel strongly either way.

@m-aciek
m-aciek marked this pull request as draft November 21, 2026 22:46
@m-aciek

m-aciek commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor Author

Sphinx itself has a utility which generates also JS translations catalog, but it doesn't expose it. I was about to create a feature request to Sphinx asking to make it public, but did an LLM-assisted research first on how other projects manage this.

I didn't find a project which does what we do in #338, all do different workarounds. Maybe it's an argument for creating a feature request in Sphinx, rather than against -- not sure.

Either way I'm now convinced that I would like to proceed with #338 rather than this, at least for science :).

The research result table:

Project Gettext executed in JavaScript? How translated strings reach JavaScript
PyData Sphinx Theme Not in the inspected component Jinja translates the text; JavaScript reads it from HTML.
Shibuya Not in the inspected component JavaScript reads translated data-* attributes.
sphinx-togglebutton No Python translates the strings and injects them into JavaScript variables.
sphinx-copybutton No A translation dictionary is maintained directly in JavaScript; the language is selected using <html lang>.
Read the Docs Theme Not in versions.js_t Gettext runs while rendering the JavaScript template at build time. Some other labels remain hardcoded in English.
Furo Not in its main script Some labels are translated in templates; others remain hardcoded in English.
IT Wallet Yes: _() and Documentation.gettext() Uses messages already available in Sphinx’s translation catalog.
Plone documentation — older example Yes: _() Adds a custom translation manually through Documentation.addTranslations().

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.

3 participants