Skip to content

Generate and load JavaScript translation catalogs - #338

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

m-aciek wants to merge 7 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 #36215804 | 📁 Comparing b85739d against latest (db635c1)

  🔍 Preview build  

156 files changed · + 1 added · ± 155 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 Resolved
Comment thread babel_runner.py Resolved
Comment thread babel_runner.py Resolved
Comment thread babel_runner.py Resolved
Comment thread babel_runner.py Resolved
@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 Resolved
Comment thread babel_runner.py Outdated
)
jsfile.write_text(
f"// {DOMAIN} translations for {pofile.parents[1].name}\n"
f"Documentation.addTranslations({serialized});\n",

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.

🤖 says this, does it matter here?


Documentation.addTranslations also replaces the global PLURAL_EXPR, and our file loads after Sphinx's translations.js, so our plural rule overrides Sphinx's. They don't always match: for German we emit a three-form rule but Sphinx's German catalog has two forms, so ngettext in searchtools.js would return undefined for most counts.

None of our three JS strings are plural, so let's merge into TRANSLATIONS and leave the plural rule to Sphinx:

        # The plural rule is global and set by Sphinx's own catalog
        if message.pluralizable:
            continue
        if message.fuzzy or not message.string:
            continue
        messages[message.id] = message.string
    serialized = json.dumps(messages, ensure_ascii=True, sort_keys=True)
    jsfile.write_text(
        f"// {DOMAIN} translations for {pofile.parents[1].name}\n"
        f"Object.assign(Documentation.TRANSLATIONS, {serialized});\n",
        encoding="utf-8",
    )

@m-aciek m-aciek Nov 27, 2026 •

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.

That's right, thank you. Potentially we could be incorrectly overriding core Sphinx plural rules for JS messages.

I've applied a fix while keeping support for ngettext, for potential future use. b85739d What do you think?

Regarding the undefined issue in forms I've opened sphinx-doc/sphinx#14872 in Sphinx.

@m-aciek m-aciek Nov 27, 2026 •

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.

The most correct fix would be to bring support for plural rules per gettext domain in JS catalogs on Sphinx side, but I think the use of it is so niche that I'm not sure if it's worth ticketing now.

@m-aciek
m-aciek requested review from hugovk and tomasr8 November 27, 2026 16:34

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