Keep the `translated` attribute on translated nodes (#11502)

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.
This commit is contained in:
Manuel Kaufmann
2023-07-23 22:00:24 +02:00
committed by GitHub
parent d564a8ba11
commit f4a47f1401
3 changed files with 15 additions and 5 deletions

View File

@@ -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

View File

@@ -512,11 +512,6 @@ class Locale(SphinxTransform):
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):
"""

View File

@@ -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')