MyST-Parser
MyST-Parser copied to clipboard
Numbered headings (for example starting with 1.) are not translated with Sphinx
What version of myst-parser
are you using?
v2.0.0-18-g330e96a
What version dependencies are you using?
$ pip list
Package Version Editable project location
----------------------------- ---------- -----------------------------------
accessible-pygments 0.0.4
alabaster 0.7.13
astroid 3.0.2
asttokens 2.4.1
Babel 2.14.0
beautifulsoup4 4.12.2
cachetools 5.3.2
certifi 2023.11.17
cfgv 3.4.0
chardet 5.2.0
charset-normalizer 3.3.2
colorama 0.4.6
coverage 7.4.0
decorator 5.1.1
distlib 0.3.8
docutils 0.19
exceptiongroup 1.2.0
executing 2.0.1
filelock 3.13.1
identify 2.5.33
idna 3.6
imagesize 1.4.1
iniconfig 2.0.0
ipython 8.19.0
jedi 0.19.1
Jinja2 3.1.2
linkify-it-py 2.0.2
markdown-it-py 3.0.0
MarkupSafe 2.1.3
matplotlib-inline 0.1.6
mdit-py-plugins 0.4.0
mdurl 0.1.2
myst-parser 2.0.0 /home/nicolas/Documents/MyST-Parser
nodeenv 1.8.0
packaging 23.2
parso 0.8.3
pexpect 4.9.0
pip 22.0.2
platformdirs 4.1.0
pluggy 1.3.0
pre-commit 3.6.0
prompt-toolkit 3.0.43
ptyprocess 0.7.0
pure-eval 0.2.2
pydata-sphinx-theme 0.13.0rc4
Pygments 2.17.2
pyproject-api 1.6.1
pytest 7.4.4
pytest-cov 4.1.0
pytest-datadir 1.5.0
pytest_param_files 0.6.0
pytest-regressions 2.5.0
PyYAML 6.0.1
requests 2.31.0
ruamel.yaml 0.18.5
ruamel.yaml.clib 0.2.8
setuptools 59.6.0
six 1.16.0
snowballstemmer 2.2.0
soupsieve 2.5
Sphinx 6.2.1
sphinx-autodoc2 0.5.0
sphinx-book-theme 1.0.0rc2
sphinx-copybutton 0.5.2
sphinx-design2 0.4.0
sphinx_pyscript 0.1.0
sphinx_pytest 0.2.0
sphinx_tippy 0.4.1
sphinx-togglebutton 0.3.2
sphinxcontrib-applehelp 1.0.7
sphinxcontrib-devhelp 1.0.5
sphinxcontrib-htmlhelp 2.0.4
sphinxcontrib-jsmath 1.0.1
sphinxcontrib-qthelp 1.0.6
sphinxcontrib-serializinghtml 1.1.9
sphinxext-opengraph 0.9.1
sphinxext-rediraffe 0.2.7
stack-data 0.6.3
tomli 2.0.1
tox 4.11.4
traitlets 5.14.0
typing_extensions 4.9.0
uc-micro-py 1.0.2
urllib3 2.1.0
virtualenv 20.25.0
wcwidth 0.2.12
wheel 0.37.1
What operating system are you using?
Linux
Describe the Bug
When a heading is manually numbered: starts with a number followed by a dot then a space, it is not translated in the Sphinx output. While the following works as expected in rST:
python -m virtualenv .venv
. .venv/bin/activate
pip install sphinx==7.1.2
sphinx-quickstart --sep -p test -a test -v test -r test -l en
echo '1. Hello world
==============
' > source/index.rst
mkdir -p source/locales/fr/LC_MESSAGES
echo '#: ../../source/index.rst:1
msgid "1. Hello world"
msgstr "1. Bonjour monde"
' > source/locales/fr/LC_MESSAGES/index.po
make html O='-Dlanguage=fr -v'
sed -n '32,36p' build/html/index.html
Which outputs:
<section id="hello-world">
<h1>1. Bonjour monde<a class="headerlink" href="#hello-world" title="Lien permanent vers cette rubrique">¶</a></h1>
</section>
Expected Behavior
The headings should be translated.
To Reproduce
Here is a diff for the tests that shows this issue:
diff --git a/tests/test_sphinx/sourcedirs/gettext/fr/LC_MESSAGES/index.po b/tests/test_sphinx/sourcedirs/gettext/fr/LC_MESSAGES/index.po
index 43e5320..943eb23 100644
--- a/tests/test_sphinx/sourcedirs/gettext/fr/LC_MESSAGES/index.po
+++ b/tests/test_sphinx/sourcedirs/gettext/fr/LC_MESSAGES/index.po
@@ -125,3 +125,6 @@ msgid ".. image:: fun-fish.png\n"
" :alt: Fun Fish 3"
msgstr ".. image:: poisson-amusant.png\n"
" :alt: Poisson amusant 3"
+
+msgid "1. numbered title"
+msgstr "1. titre numéroté"
diff --git a/tests/test_sphinx/sourcedirs/gettext/index.md b/tests/test_sphinx/sourcedirs/gettext/index.md
index a721944..05998e3 100644
--- a/tests/test_sphinx/sourcedirs/gettext/index.md
+++ b/tests/test_sphinx/sourcedirs/gettext/index.md
@@ -61,3 +61,5 @@ doctest block
```{figure} fun-fish.png
:alt: Fun Fish 3
```
+
+## 1. numbered title
diff --git a/tests/test_sphinx/test_sphinx_builds/test_gettext.pot b/tests/test_sphinx/test_sphinx_builds/test_gettext.pot
index 933b8b6..4d8b7d2 100644
--- a/tests/test_sphinx/test_sphinx_builds/test_gettext.pot
+++ b/tests/test_sphinx/test_sphinx_builds/test_gettext.pot
@@ -79,3 +79,7 @@ msgstr ""
#: ../../index.md:61
msgid "Fun Fish 3"
msgstr ""
+
+#: ../../index.md:65
+msgid "1. numbered title"
+msgstr ""
diff --git a/tests/test_sphinx/test_sphinx_builds/test_gettext_additional_targets.pot b/tests/test_sphinx/test_sphinx_builds/test_gettext_additional_targets.pot
index 11c51d4..7cb2f53 100644
--- a/tests/test_sphinx/test_sphinx_builds/test_gettext_additional_targets.pot
+++ b/tests/test_sphinx/test_sphinx_builds/test_gettext_additional_targets.pot
@@ -127,3 +127,7 @@ msgstr ""
#: ../../index.md:61
msgid "Fun Fish 3"
msgstr ""
+
+#: ../../index.md:65
+msgid "1. numbered title"
+msgstr ""
diff --git a/tests/test_sphinx/test_sphinx_builds/test_gettext_html.html b/tests/test_sphinx/test_sphinx_builds/test_gettext_html.html
index 469e188..0db99d0 100644
--- a/tests/test_sphinx/test_sphinx_builds/test_gettext_html.html
+++ b/tests/test_sphinx/test_sphinx_builds/test_gettext_html.html
@@ -156,6 +156,14 @@
<figure class="align-default">
<img alt="Poisson amusant 3" src="_images/fun-fish.png"/>
</figure>
+ <section id="numbered-title">
+ <h2>
+ 1. titre numéroté
+ <a class="headerlink" href="#numbered-title" title="Lien permanent vers cette rubrique">
+ ¶
+ </a>
+ </h2>
+ </section>
</section>
</div>
</div>
diff --git a/tests/test_sphinx/test_sphinx_builds/test_gettext_html.resolved.xml b/tests/test_sphinx/test_sphinx_builds/test_gettext_html.resolved.xml
index 231ca33..0eb02c1 100644
--- a/tests/test_sphinx/test_sphinx_builds/test_gettext_html.resolved.xml
+++ b/tests/test_sphinx/test_sphinx_builds/test_gettext_html.resolved.xml
@@ -91,3 +91,6 @@
<image alt="Poisson amusant 2" candidates="{'*': 'fun-fish.png'}" uri="fun-fish.png">
<figure>
<image alt="Poisson amusant 3" candidates="{'*': 'fun-fish.png'}" uri="fun-fish.png">
+ <section ids="numbered-title" names="1.\ numbered\ title 1.\ titre\ numéroté">
+ <title>
+ 1. titre numéroté
diff --git a/tests/test_sphinx/test_sphinx_builds/test_gettext_html.xml b/tests/test_sphinx/test_sphinx_builds/test_gettext_html.xml
index dfc5f41..aae502a 100644
--- a/tests/test_sphinx/test_sphinx_builds/test_gettext_html.xml
+++ b/tests/test_sphinx/test_sphinx_builds/test_gettext_html.xml
@@ -91,3 +91,6 @@
<image alt="Poisson amusant 2" candidates="{'*': 'fun-fish.png'}" uri="fun-fish.png">
<figure>
<image alt="Poisson amusant 3" candidates="{'*': 'fun-fish.png'}" uri="fun-fish.png">
+ <section ids="numbered-title" names="1.\ numbered\ title 1.\ titre\ numéroté">
+ <title>
+ 1. titre numéroté
And here is pytest's output with this patch applied:
E AssertionError: FILES DIFFER:
E /tmp/pytest-of-nicolas/pytest-44/test_gettext_html0/test_sphinx_builds/test_gettext_html.xml
E /tmp/pytest-of-nicolas/pytest-44/test_gettext_html0/test_sphinx_builds/test_gettext_html.obtained.xml
E HTML DIFF: /tmp/pytest-of-nicolas/pytest-44/test_gettext_html0/test_sphinx_builds/test_gettext_html.obtained.diff.html
E ---
E +++
E @@ -91,6 +91,6 @@
E <image alt="Poisson amusant 2" candidates="{'*': 'fun-fish.png'}" uri="fun-fish.png">
E <figure>
E <image alt="Poisson amusant 3" candidates="{'*': 'fun-fish.png'}" uri="fun-fish.png">
E - <section ids="numbered-title" names="1.\ numbered\ title 1.\ titre\ numéroté">
E + <section ids="numbered-title" names="1.\ numbered\ title">
E <title>
E - 1. titre numéroté
E + 1. numbered title
tests/test_sphinx/conftest.py:135: AssertionError
After a debugging session, it seems to be again, somewhat related to https://github.com/sphinx-doc/sphinx/issues/8852