Skip to content

Commit

Permalink
Image nodes are handled separately, and literal can simply be manuall…
Browse files Browse the repository at this point in the history
…y patched
  • Loading branch information
n-peugnet committed Apr 7, 2024
1 parent 3c97944 commit 66b14d3
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions sphinx/transforms/i18n.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
from sphinx.util.i18n import docname_to_domain
from sphinx.util.index_entries import split_index_msg
from sphinx.util.nodes import (
IMAGE_TYPE_NODES,
LITERAL_TYPE_NODES,
NodeMatcher,
extract_messages,
Expand Down Expand Up @@ -444,14 +443,17 @@ def apply(self, **kwargs: Any) -> None:
node['uri'] = msgstr
continue

# literalblock and images do not need to be parsed as they do not contain inline syntax
if isinstance(node, LITERAL_TYPE_NODES + IMAGE_TYPE_NODES):
patch = nodes.paragraph(text=msgstr)
else:
patch = publish_msgstr(self.app, msgstr, source,
node.line, self.config, settings) # type: ignore[arg-type]
# literalblock do not need to be parsed as they do not contain inline syntax
if isinstance(node, LITERAL_TYPE_NODES):
node.children = [nodes.Text(msgstr)]
# for highlighting that expects .rawsource and .astext() are same.
node.rawsource = node.astext()
node['translated'] = True
continue

patch = publish_msgstr(self.app, msgstr, source,
node.line, self.config, settings) # type: ignore[arg-type]

# Structural Subelements phase2
# ignore unexpected markups in translation message
if not isinstance(patch, nodes.paragraph):
continue # skip
Expand All @@ -464,10 +466,6 @@ def apply(self, **kwargs: Any) -> None:
updater.update_pending_xrefs()
updater.update_leaves()

# for highlighting that expects .rawsource and .astext() are same.
if isinstance(node, LITERAL_TYPE_NODES):
node.rawsource = node.astext()

node['translated'] = True # to avoid double translation

if 'index' in self.config.gettext_additional_targets:
Expand Down

0 comments on commit 66b14d3

Please sign in to comment.