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

Some block element's titles are not picked up for translation #9947

Closed
liborjelinek opened this issue Dec 6, 2021 · 1 comment · Fixed by #9953
Closed

Some block element's titles are not picked up for translation #9947

liborjelinek opened this issue Dec 6, 2021 · 1 comment · Fixed by #9953

Comments

@liborjelinek
Copy link
Contributor

liborjelinek commented Dec 6, 2021

Describe the bug

Titles of block elements are not properly picked up by "make gettext" if the block body contains a bullet list or paragraph followed by a bullet list.

I discovered it and test it with topic block, maybe other admonition-style blocks are suffering the issue too.

All titles in the following topic are extracted to POT:

.. topic:: Topic Title

   Topic Content

.. topic:: 1. Topic Title

   Topic Content

.. topic:: 2. Topic Title

   - Bullet List Item

   Topic Content

.. topic:: 3. Topic Title

   Topic Content

   Topic Content

but the two titles will NOT be added to POT:

.. topic:: 4. Topic Title

   Topic Content

   - Bullet List Item

.. topic:: 5. Topic Title

   - Bullet List Item

Very strange.

How to Reproduce

In my forked repo, I extended test_gettext_topic test to demonstrate it (and to fail at this moment). Please see liborjelinek@0f7eda4.

$ git clone https://github.com/mattdocumatt/sphinx
$ git checkout l18n-doesnt-extract-some-titles
$ cd sphinx
$ pip install -e .
$ pip install pytest html5lib

and finally failing test

$ pytest tests/test_intl.py::test_gettext_topic

Expected behavior

In the above example, msgid for "4. Topic Title" and "5. Topic Title" created in POT.

Your project

https://github.com/mattdocumatt/sphinx/tree/i18n-doesnt-extract-some-titles

Screenshots

No response

OS

macOS

Python version

3.8.2

Sphinx version

latest

Sphinx extensions

No response

Extra tools

No response

Additional context

I found a similar issue #4938 was discussed in the past. It was fixed but I feel it is related to this one.

According to my local debugging, two failing titles from the above example, are not extracted because they have no node.source and are excluded in sphinx.util.nodes.is_translatable(), at this if check

if isinstance(node, nodes.TextElement):
        if not node.source:
            logger.debug('[i18n] SKIP %r because no node.source: %s',
                         get_full_module_name(node), repr_domxml(node))

because they are not "patched" with the source code line number in apply_source_workaround(). If I'm logging patching and skipping, they of affected title, it looks very chaotic - in large project, few times patched, few times skipped, and finally skipped forever.

In test-intl and 4. Topic Title:

$ cd tests/roots/test-intl
$ sphinx-build -vvv -b gettext . _build/gettext | grep '4. Topic Title'
[i18n] PATCH: 'docutils.nodes.title' to have source: <title>4. Topic Title</title>
[i18n] SKIP 'docutils.nodes.title' because no node.source: <title>4. Topic Title</title>
[i18n] SKIP 'docutils.nodes.title' because no node.source: <title>4. Topic Title</title>

But title 5. Topic Title is only skipped once:

sphinx-build -vvv -b gettext . _build/gettext | grep '5. Topic Title'
[i18n] SKIP 'docutils.nodes.title' because no node.source: <title>5. Topic Title</title>
@tk0miya
Copy link
Member

tk0miya commented Dec 8, 2021

Note: It seems docutils does not fill the topic node with the source info when the topic directive has a bullet list.

from docutils.core import publish_doctree


# topic directive with a paragraph
s = """
.. topic:: 5. Topic Title

   Paragraph
"""

(topic,) = publish_doctree(s)
print(topic.source, topic.line)


# topic directive with a bullet list
s = """
.. topic:: 5. Topic Title

   - Bullet List Item
"""

(topic,) = publish_doctree(s)
print(topic.source, topic.line)
$ python test.py
<string> None
None None

tk0miya added a commit to tk0miya/sphinx that referenced this issue Dec 9, 2021
… be translatable

It seems docutils does not fill the topic node with the source info when
a topic directive has a bullet list.  As a workaround, This fills the
source info of them.
@tk0miya tk0miya added this to the 4.4.0 milestone Dec 9, 2021
tk0miya added a commit that referenced this issue Dec 11, 2021
Fix #9947: i18n: topic directive having a bullet list can't be translatable
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 11, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants