Skip to content

Generate and load JavaScript translation catalogs - #338

Open
m-aciek wants to merge 6 commits into
python:mainfrom
m-aciek:js-copy-button-translations
Open

m-aciek wants to merge 6 commits into
python:mainfrom
m-aciek:js-copy-button-translations

Conversation

@m-aciek

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

Copy link
Copy Markdown
Contributor

Alternative to #337.

Add and mount missing JS translations catalog. Extraction was/is working correctly.

@read-the-docs-community

read-the-docs-community Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

Documentation build overview

📚 python-docs-theme-previews | 🛠️ Build #36145428 | 📁 Comparing 4269a8e against latest (db635c1)

  🔍 Preview build  

151 files changed · + 1 added · ± 150 modified

+ Added

± Modified

@m-aciek
m-aciek marked this pull request as ready for review November 21, 2026 22:46
Comment thread babel_runner.py Resolved
Comment thread pyproject.toml Resolved
…rtifact paths alphabetically in pyproject.toml
Comment thread babel_runner.py Outdated
Comment on lines +124 to +129
"""Export translated singular JavaScript messages from the compiled catalog."""
mofile = pofile.with_suffix(".mo")
jsfile = pofile.with_suffix(".js")
if not mofile.exists():
jsfile.unlink(missing_ok=True)
return

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could simplify this function to only read the .po file, and skip the fuzzy/untranslated messages, rather than also reading the compiled .mo file?

Suggested change
"""Export translated singular JavaScript messages from the compiled catalog."""
mofile = pofile.with_suffix(".mo")
jsfile = pofile.with_suffix(".js")
if not mofile.exists():
jsfile.unlink(missing_ok=True)
return
"""Export translated singular JavaScript messages from the catalog."""
jsfile = pofile.with_suffix(".js")

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for suggestion, applied. On the other hand using .mo makes us reusing the same configuration of catalog compilation, but it's not worth the complication probably.

Comment thread babel_runner.py Outdated
Comment on lines +132 to +133
with mofile.open("rb") as f:
compiled = read_mo(f)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
with mofile.open("rb") as f:
compiled = read_mo(f)

Comment thread babel_runner.py Outdated
compiled = read_mo(f)
messages = {}
for message in source:
if not isinstance(message.id, str):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if not isinstance(message.id, str):
if not isinstance(message.id, str) or message.fuzzy or not message.string:

Comment thread babel_runner.py Outdated
Comment on lines +140 to +142
translation = compiled.get(message.id)
if translation is not None and translation.string:
messages[message.id] = translation.string

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
translation = compiled.get(message.id)
if translation is not None and translation.string:
messages[message.id] = translation.string
messages[message.id] = message.string

Comment thread babel_runner.py Outdated
import tomllib
from pathlib import Path

from babel.messages.mofile import read_mo

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
from babel.messages.mofile import read_mo

@tomasr8

tomasr8 commented Nov 22, 2026

Copy link
Copy Markdown
Member

Thanks for doing the work @m-aciek! I should have time tomorrow for a review :)

Comment thread babel_runner.py Resolved
Comment thread babel_runner.py Resolved
Affirm-Session: 01a20a8a-1869-7c52-8e68-246dde4499c5
Affirm-Session: 01a20a8a-1869-7c52-8e68-246dde4499c5

@tomasr8 tomasr8 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, but I'll let Hugo have another look :)

Comment thread babel_runner.py Outdated
for message in source:
if not any(filename.endswith(".js") for filename, _ in message.locations):
continue
if message.context is not None or message.fuzzy or not message.string:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I'd just add a comment mentioning we skip pgettext and why

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 I've added: skip messages with context: Sphinx's JavaScript gettext runtime doesn't provide pgettext().

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update: also splitted the condition and simplified to Sphinx's JavaScript gettext runtime doesn't provide pgettext().

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