mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
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:
1
CHANGES
1
CHANGES
@@ -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
|
||||
|
||||
@@ -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):
|
||||
"""
|
||||
|
||||
@@ -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')
|
||||
|
||||
Reference in New Issue
Block a user