Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Template translations (sphinx.po) are not used for English language #12214

Open
n-peugnet opened this issue Mar 30, 2024 · 0 comments · May be fixed by #12220
Open

Template translations (sphinx.po) are not used for English language #12214

n-peugnet opened this issue Mar 30, 2024 · 0 comments · May be fixed by #12220
Labels

Comments

@n-peugnet
Copy link
Contributor

n-peugnet commented Mar 30, 2024

Describe the bug

When using custom template overrides as described in https://www.sphinx-doc.org/en/master/development/templating.html

If the template contains translated strings, for instance:

{% extends "!layout.html" %}
{% block document %}
    {{ _('coucou') }}
    {{ super() }}
{% endblock %}

The strings are correctly extracted with the gettext builder (make gettext), but when the base language is not English, and the translated language is English, the translation catalog is not used. It works as expected when translating in another language than English (for example from French to German).

How to Reproduce

I made a reproducer in this git repo: https://github.com/n-peugnet/sphinx-template-en-translation-bug or this zip:
sphinx-template-en-translation-bug-main.zip

git clone https://github.com/n-peugnet/sphinx-template-en-translation-bug
cd sphinx-template-en-translation-bug
make html O=-Dlanguage=en

Then check the content of _build/html/index.html

Environment Information

Platform:              linux; (Linux-6.6.15-amd64-x86_64-with-glibc2.37)
Python version:        3.11.8 (main, Feb  7 2024, 21:52:08) [GCC 13.2.0])
Python implementation: CPython
Sphinx version:        7.3.0
Docutils version:      0.20.1
Jinja2 version:        3.1.3
Pygments version:      2.17.2

Sphinx is latest git version: v7.2.6-318-gd5baa46d8

Sphinx extensions

No response

Additional context

Notice that running make html O=-Dlanguage=de produces the expected result.

n-peugnet added a commit to n-peugnet/sphinx that referenced this issue Apr 1, 2024
The English language was hardcoded to load empty translations for
templates as part of sphinx-doc#10067,
but the rest of the code is already capable of handling missing
translations just fine, so we can simply drop the first if block.

This allows to use translations for English in custom templates, as for
all the other languages.

Fixes sphinx-doc#12214
@n-peugnet n-peugnet linked a pull request Apr 1, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant