How to translate comments in code blocks

59 views
Skip to first unread message

Yaroslav Nikitenko

unread,
May 3, 2020, 8:25:04 AM5/3/20
to sphinx-users
Hello,

I have code examples in the documentation (defined as code-blocks,
both literally included and just typed inline). In these code examples
there are comments, but when I produce documentation translation, they
are not extracted into .po files, and obviously are not translated.

How can I translate these comments in code examples?

I asked this on stackoverflow, there is an example of a code block if
really needed (https://stackoverflow.com/questions/61248191/how-to-translate-comments-in-code-blocks-using-sphinx).

Many thanks.

Best regards,
Yaroslav Nikitenko

Matt from Documatt

unread,
May 3, 2020, 9:03:04 AM5/3/20
to sphinx...@googlegroups.com
It's impossible. Sphinx will have to understand comments in every language.

If you want to translate comments in code-block (and literal blocks after ::), you must translate them all. Add gettext_additional_targets = ["literal-block"] to your conf.py and re-run POT/PO update.

Matt

--
You received this message because you are subscribed to the Google Groups "sphinx-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sphinx-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sphinx-users/CA%2BRLzGAzko4FA2VJ6qHioU-uV%3D4kxisgRYhOPCUapqJX8cZ8ww%40mail.gmail.com.

Yaroslav Nikitenko

unread,
May 3, 2020, 10:50:22 AM5/3/20
to sphinx...@googlegroups.com
Many thanks. This works wonderfully!

As a side note, I think that Python is not "every language". This is
the default language in Sphinx. Anyway, I understand that this is not
implemented, and this can be solved manually.
I'll add this answer to my question on stackoverflow (with the
reference to you and to this mailing list).

Cheers,
Yaroslav
> https://groups.google.com/d/msgid/sphinx-users/CAOGNDW_CwLjTh-LC9mAh5a3M6Cf-QXRkE-7aJKtuu%3D%2B7%2B%3DyMQg%40mail.gmail.com.
>


--
С уважением,
Ярослав Никитенко
http://twitter.com/ynikitenko
http://vk.com/yaroslav.nikitenko
http://facebook.com/ynikitenko
+7 916 743 3759
Reply all
Reply to author
Forward
0 new messages