问题
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