summaryrefslogtreecommitdiff
path: root/sphinx/util/nodes.py
diff options
context:
space:
mode:
authorTakeshi KOMIYA <i.tkomiya@gmail.com>2020-07-19 02:12:41 +0900
committerTakeshi KOMIYA <i.tkomiya@gmail.com>2020-07-19 12:58:28 +0900
commit897be0ebae09117d64222dcee23daa80d32a28cb (patch)
tree223fe4d4680c9a0151011d1c76955cbf99c0fadb /sphinx/util/nodes.py
parent82a149f4f33ad3f36d96590b58006e64c6bada59 (diff)
downloadsphinx-git-897be0ebae09117d64222dcee23daa80d32a28cb.tar.gz
Close #7784: i18n: The alt text for image is translated by default
Make alt text for image translatable by default without settings of gettext_additional_targets.
Diffstat (limited to 'sphinx/util/nodes.py')
-rw-r--r--sphinx/util/nodes.py16
1 files changed, 10 insertions, 6 deletions
diff --git a/sphinx/util/nodes.py b/sphinx/util/nodes.py
index e360ffb7f..099866d66 100644
--- a/sphinx/util/nodes.py
+++ b/sphinx/util/nodes.py
@@ -197,6 +197,10 @@ def is_translatable(node: Node) -> bool:
if isinstance(node, addnodes.translatable):
return True
+ # image node marked as translatable or having alt text
+ if isinstance(node, nodes.image) and (node.get('translatable') or node.get('alt')):
+ return True
+
if isinstance(node, nodes.Inline) and 'translatable' not in node: # type: ignore
# inline node must not be translated if 'translatable' is not set
return False
@@ -224,9 +228,6 @@ def is_translatable(node: Node) -> bool:
return False
return True
- if isinstance(node, nodes.image) and node.get('translatable'):
- return True
-
if isinstance(node, addnodes.meta):
return True
if is_pending_meta(node):
@@ -259,10 +260,13 @@ def extract_messages(doctree: Element) -> Iterable[Tuple[Element, str]]:
msg = node.rawsource
if not msg:
msg = node.astext()
- elif isinstance(node, IMAGE_TYPE_NODES):
- msg = '.. image:: %s' % node['uri']
+ elif isinstance(node, nodes.image):
if node.get('alt'):
- msg += '\n :alt: %s' % node['alt']
+ yield node, node['alt']
+ if node.get('translatable'):
+ msg = '.. image:: %s' % node['uri']
+ else:
+ msg = None
elif isinstance(node, META_TYPE_NODES):
msg = node.rawcontent
elif isinstance(node, nodes.pending) and is_pending_meta(node):