Sphinx文档:conf.py变量的转换(i18n) [英] Sphinx documentation: translation (i18n) of conf.py variables

查看:61
本文介绍了Sphinx文档:conf.py变量的转换(i18n)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在sphinx文档项目中,如何将翻译添加到 conf.py 中定义的变量中?

In a sphinx documentation project, how to add translations to the variables defined in conf.py?

要点: project 变量是<品牌名称>设置和配置手册" ,在此我希望翻译后一部分.

Case in point: The project Variable is "<Brand Name> Setup and Configuration Manual", where I would like to have the latter part translated.

使用标准的i18n设施,这些 .pot 文件中的值将丢失.我也找不到如何在 conf.py 中使用命令行指定的语言(通过硬编码字典进行翻译).

Using the standard i18n facilities, those values are missing from the .pot files. I also could not find out how to get at the commandline-specified language within conf.py (to translate via hardcoded dictionary).

推荐答案

如上面的评论中所述,当前是一个未解决的问题.

As mentioned in the comments above, this is currently an open issue.

可以通过标签将信息传递给conf.py(仅).

It is possible to pass information to conf.py (only) by means of tags.

在命令行上,使用 -t language_de 而不是 -D language = de ,以定义包含区域设置ID的标记.

On the commandline, use -t language_de instead of -D language=de, in order to define a tag containing the locale id.

conf.py 中,使用以下命令捕获标记:

In conf.py, catch the tag by using:

language = None
for t in tags:
    if t.startswith('language_'):
        language = t[9:]

然后可以省略 -D language = .. 命令行,因为 conf.py 中的 language 变量具有相同的作用

The -D language=.. command line can then be omitted, since the language variable in conf.py has the same effect.

一旦我们获得了语言价值,便可以使用字典进行翻译:

Once we got the language value, translation can be done with a dictionary:

project = {
    'de': u'<Brand Name> Setup-und Konfigurationshandbuch',
    # ... more translations ...
}.get(language, u'<Brand Name> Setup and Configuration Manual')

这篇关于Sphinx文档:conf.py变量的转换(i18n)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆