Sphinx documentation: translation (i18n) of conf.py variables

二次信任 提交于 2021-01-29 02:50:40

问题


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

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

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).


回答1:


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

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

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

In conf.py, catch the tag by using:

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

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')


来源:https://stackoverflow.com/questions/55808716/sphinx-documentation-translation-i18n-of-conf-py-variables

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!