【发布时间】:2020-04-16 10:37:38
【问题描述】:
我使用Sphinx 为一个项目编写文档。我有代码示例(定义为code-blocks,包括字面意思和内联类型)。在这些代码示例中有cmets,但是当我制作文档翻译时,它们没有被提取到.po文件中,显然没有被翻译。
如何翻译代码示例中的 cmets?
我发现了有关 Sphinx 修改的其他问题。答案建议修改conf.py(制作一些钩子),创建roles 或extensions。我以前从未这样做过,我不知道从哪里开始,什么解决方案会更好。这个问题有现成的解决方案吗?
UPD。这些是我想在我的文档中展示的代码示例:
git clone https://github.com/ynikitenko/lena
# most of requirements are for development only
pip install -r lena/requirements.txt
(这里我想翻译评论)。一个更困难(也许不需要)的例子是:
class End(object):
"""Stop sequence here."""
def run(self, flow):
"""Exhaust all preceding flow and stop iteration
(yield nothing to the following flow).
"""
for val in flow:
pass
return
# otherwise it won't be a generator
yield "unreachable"
这些示例使用指令格式化
.. code-block::
【问题讨论】:
-
你能用一个例子澄清你的意思吗?喜欢 cmets 长什么样,想看什么样的代码示例。
-
@zkytony 当然。例如,这是一个内联注释lena.readthedocs.io/en/latest/#from-pypi 我想翻译“# if you plan to render LaTeX templates”。更大的代码示例可能在这里,带有完整的文档字符串(但这种情况可能不太重要):lena.readthedocs.io/en/latest/tutorial/answers.html#ex-1。
-
@zkytony 我在问题中添加了这个,谢谢你的提问。
标签: internationalization python-sphinx