Skip to content

Commit

Permalink
Keep the translated attribute on translated nodes (#11502)
Browse files Browse the repository at this point in the history
This particular commit ensures that the ``translated`` attribute
is retained on translated nodes so that developers may use it
to improve the experience on translations.
This attribute can be useful to calculate
the translated percentage of a particular document,
to visually mark paragraphs as not translated,
and many other applications.
  • Loading branch information
humitos committed Jul 23, 2023
1 parent d564a8b commit f4a47f1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGES
Expand Up @@ -18,6 +18,7 @@ Deprecated
Features added
--------------

* #11157: Keep ``translated: True`` attribute on translated nodes.
* #11415: Add a checksum to JavaScript and CSS asset URIs included within
generated HTML, using the CRC32 algorithm.
* :meth:`~sphinx.application.Sphinx.require_sphinx` now allows the version
Expand Down
5 changes: 0 additions & 5 deletions sphinx/transforms/i18n.py
Expand Up @@ -512,11 +512,6 @@ def apply(self, **kwargs: Any) -> None:
node['raw_entries'] = entries
node['entries'] = new_entries

# remove translated attribute that is used for avoiding double translation.
matcher = NodeMatcher(translated=Any)
for translated in self.document.findall(matcher): # type: nodes.Element
translated.delattr('translated')


class RemoveTranslatableInline(SphinxTransform):
"""
Expand Down
14 changes: 14 additions & 0 deletions tests/test_intl.py
Expand Up @@ -615,6 +615,20 @@ def test_gettext_buildr_ignores_only_directive(app):
assert expect_msg.id in [m.id for m in actual if m.id]


@sphinx_intl
def test_node_translated_attribute(app):
app.build()

expected = 23
translated_nodes = 0

doctree = app.env.get_doctree('admonitions')
for node in doctree.traverse():
if hasattr(node, 'get') and node.get('translated', False):
translated_nodes += 1
assert translated_nodes == expected


@sphinx_intl
# use individual shared_result directory to avoid "incompatible doctree" error
@pytest.mark.sphinx(testroot='builder-gettext-dont-rebuild-mo')
Expand Down

0 comments on commit f4a47f1

Please sign in to comment.