Skip to content

Commit 3338093

Browse files
committed
Translator on current builder
We set our own translator in the translators defined by other extensions, but also for the current builder. It may happen that there is an extension that defines two translators for `dirhml` and `json`, and we are going to override them --the problem comes when `sphinx-build` is called with `-b custombuilder` since we weren't overriding it in that case. This commit override the ones defined by the user, but also the default one.
1 parent 3b49a4c commit 3338093

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

hoverxref/extension.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -147,31 +147,31 @@ def setup_translators(app):
147147
and our own ``HoverXRefHTMLTranslatorMixin`` that includes the logic to
148148
``_hoverxref`` attributes.
149149
"""
150-
if not app.registry.translators.items():
150+
for name, klass in app.registry.translators.items():
151+
if app.builder.format != 'html':
152+
# Skip translators that are not HTML
153+
continue
154+
151155
translator = types.new_class(
152156
'HoverXRefHTMLTranslator',
153157
(
154158
HoverXRefHTMLTranslatorMixin,
155-
app.builder.default_translator_class,
159+
klass,
156160
),
157161
{},
158162
)
159-
app.set_translator(app.builder.name, translator, override=True)
160-
else:
161-
for name, klass in app.registry.translators.items():
162-
if app.builder.format != 'html':
163-
# Skip translators that are not HTML
164-
continue
165-
166-
translator = types.new_class(
167-
'HoverXRefHTMLTranslator',
168-
(
169-
HoverXRefHTMLTranslatorMixin,
170-
klass,
171-
),
172-
{},
173-
)
174-
app.set_translator(name, translator, override=True)
163+
app.set_translator(name, translator, override=True)
164+
165+
translator = types.new_class(
166+
'HoverXRefHTMLTranslator',
167+
(
168+
HoverXRefHTMLTranslatorMixin,
169+
app.builder.default_translator_class,
170+
),
171+
{},
172+
)
173+
app.set_translator(app.builder.name, translator, override=True)
174+
175175

176176

177177
def is_hoverxref_configured(app, config):

0 commit comments

Comments
 (0)