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
Keep "translated" attribute on translated nodes #11502
Keep "translated" attribute on translated nodes #11502
Conversation
`sphinx.transforms.Locale` iterates over all the nodes to replace its content with the translated version of the text if found. Since the process works in two phases, it adds an "internal" `translated: True` attribute to the docutils node when the translated text is found in phase 1, allowing phase 2 to skip this nodes and avoid re-processing them. Finally, this "internal" `translated` attribute is removed from all the nodes. This particular commit deletes the code that removes the `translated` attribute from the nodes so developers can 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.
bde0d9c
to
9b50436
Compare
The tests need fixing -- likely the problem is A |
We cannot share results because the pickled doctree is not compatible between Sphinx versions.
That makes sense. Thanks! 👍🏼 . I pushed a new commit. I think it should pass all the tests now. |
Does #3588 still apply? That was the reason A |
Good point. It seems that it only affects HTML4 writer since the method If we want to keep supporting HTML4, we could remove those attributes in another
So, I suppose we are safe keeping this |
I created the HTML file using the latest Sphinx 7.0.1 and another using the development version from this PR (with the ▶ diff -u sphinx-latest.html sphinx-pr-development.html
--- sphinx-latest.html 2023-07-23 20:32:16.329349599 +0200
+++ sphinx-pr-development.html 2023-07-23 20:32:28.145932780 +0200
@@ -6,13 +6,13 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Hola mundo traducido — documentación de Python - </title>
- <link rel="stylesheet" type="text/css" href="_static/pygments.css" />
- <link rel="stylesheet" type="text/css" href="_static/alabaster.css" />
- <link rel="stylesheet" type="text/css" href="_static/translated.css" />
- <script data-url_root="./" id="documentation_options" src="_static/documentation_options.js"></script>
- <script src="_static/doctools.js"></script>
- <script src="_static/sphinx_highlight.js"></script>
- <script src="_static/translations.js"></script>
+ <link rel="stylesheet" type="text/css" href="_static/pygments.css?v=b3523f8e" />
+ <link rel="stylesheet" type="text/css" href="_static/alabaster.css?v=039e1c02" />
+ <link rel="stylesheet" type="text/css" href="_static/translated.css?v=dbb70219" />
+ <script data-url_root="./" id="documentation_options" src="_static/documentation_options.js?v=0828dd0a"></script>
+ <script src="_static/doctools.js?v=888ff710"></script>
+ <script src="_static/sphinx_highlight.js?v=4825356b"></script>
+ <script src="_static/translations.js?v=b95a766b"></script>
<link rel="index" title="Índice" href="genindex.html" />
<link rel="search" title="Búsqueda" href="search.html" />
@@ -32,15 +32,15 @@
<div class="body" role="main">
<section id="hello-translated-world">
-<h1>Hola mundo traducido<a class="headerlink" href="#hello-translated-world" title="Enlace permanente a este encabezado">¶</a></h1>
+<h1 class="translated">Hola mundo traducido<a class="headerlink" href="#hello-translated-world" title="Enlace permanente a este encabezado">¶</a></h1>
<p>This is a minimal example of how developers can use the <code class="docutils literal notranslate"><span class="pre">translated</span></code> node attribute to build different Sphinx extensions.
It highlights (in green) via CSS the translated paragraphs and shows the translated percetange of each document.</p>
<div class="admonition note">
<p class="admonition-title">Nota</p>
<p>The source language is English and the target language is Spanish.</p>
</div>
-<p>This file is translated at 0.0 %</p>
-<p>Este archivo está escrito en inglés y será traducido al español.</p>
+<p>This file is translated at 18.181818181818183 %</p>
+<p class="translated">Este archivo está escrito en inglés y será traducido al español.</p>
<p>This paragraph should be missing the Spanish translation and it is shown in it’s original language.</p>
<p>List definition:</p>
<ul class="simple">
@@ -101,7 +101,7 @@
©.
|
- Powered by <a href="http://sphinx-doc.org/">Sphinx 7.0.1</a>
+ Powered by <a href="http://sphinx-doc.org/">Sphinx 7.1.0+/2c8909cdc</a>
& <a href="https://github.com/bitprophet/alabaster">Alabaster 0.7.13</a>
| Note the only differences are:
This means there is no HTML structure modification when keeping the |
Thanks for the detailed explanation @humitos! A |
Feature or Bugfix
Feature
Purpose
sphinx.transforms.Locale
iterates over all the nodes to replace its content with the translated version of the text if found. Since the process works in two phases, it adds an "internal"translated: True
attribute to the docutils node when the translated text is found in phase 1, allowing phase 2 to skip this nodes and avoid re-processing them. Finally, this "internal"translated
attribute is removed from all the nodes.This particular commit deletes the code that removes the
translated
attribute from the nodes so developers can 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.Example
I created a minimal example of how developers can use this
translated
attribute to develop Sphinx extensions: https://github.com/humitos/sphinx-translated-node-exampleDetail
Relates