使用 sphinx 进行不完整的翻译仅显示默认语言?

Doing incomplete translations with sphinx is showing default language only?

按照 the official 翻译文件的工作流程后,我发现自己的翻译似乎不起作用。

make gettext
sphinx-intl update -p /source/_build/gettext -l fr
set SPHINXOPTS=-D language=fr
make html

我已经成功地创建了 *.pot 和 *.po 文件并且测试翻译了这个 *.po 文件的 parts (其他 msgid 仍然默认为“”。然后我设置语言变为法语,运行 再次变成 html - 但我翻译的文本没有以法语显示。

构建输出中没有任何提示显示出了什么问题:

C:\dev\ritune\docs>make html
Sphinx v4.1.2 in Verwendung
Lade Übersetzungen [fr]…erledigt
making output directory... erledigt
[autosummary] generating autosummary for: .roles.rst, configuration\add_modules\add_modules.rst, configuration\db_dump\db_dump.rst, configuration\index.rst, configuration\modules\config_dashboard\config_dashboard.rst, configuration\modules\index.rst, configuration\plotly_diagrams\plotly_diagrams.rst, data_explorer\data_explorer.rst, functions\asset_management\asset_management.rst, functions\dashboard\dashboard.rst, ..., system\index.rst, system\logs\logs.rst, system\main_menu\main_menu.rst, system\physical\physical.rst, system\proc\proc.rst, system\settings\settings.rst, system\tags\tags.rst, system\user_profile\user_profile.rst, system\users_roles\users_roles.rst, system\versions\versions.rst
loading intersphinx inventory from https://docs.python.org/3/objects.inv...
loading intersphinx inventory from https://www.sphinx-doc.org/en/master/objects.inv...
building [mo]: targets for 0 po files that are out of date
building [html]: targets for 81 source files that are out of date
updating environment: [new config] 81 added, 0 changed, 0 removed
reading sources... [100%] system/versions/versions                             or2ntrol
looking for now-outdated files... none found
pickling environment... erledigt
checking consistency... preparing documents... erledigt
writing output... [100%] system/versions/versions                              r2ntrol
generating indices... genindex erledigt
writing additional pages... search erledigt
copying images... [100%] system/versions/version_numbering.svg                 1fcb54c2ee.png
copying downloadable files... [ 57%] modules/reporting_masks/Betriebsstatistik_Vorlage_20210514.xlsx_Betriebsstatistik_Vorlage_20210514.xlscopying downloadable files... [100%] system/alarms/ANSI-ISA-18.2 - Management of Alarm Systems for the Process Industries.PDF
copying static files... erledigt
copying extra files... erledigt
dumping search index in French (code: fr)... erledigt
dumping object inventory... erledigt
build abgeschlossen, 13 warnings.

注意我排除了与我在其中一个文件(我目前正在处理的文件)中犯的愚蠢语法错误有关的警告。

这是预期的行为还是我做错了什么?我想测试翻译功能和我的 *.po 文件。

我找到了解决方案。 Sphinx 实际上并没有接收 .mo(二进制)文件。

回溯正确工作的步骤:

  1. 确保您在根目录中并且看到 buildsource 目录
  2. 使用 sphinx gettext 将在 build/gettext
  3. 中创建 *.pot 文件
  4. 获取那些 *.pot 文件并使用 sphinx-intl update -p build/gettext -l fr 翻译成 *.po 文件(例如法语/'fr')。这将在新文件夹 locales 中创建 *.po 文件,该文件夹默认位于根目录下的 buildsource 目录中。
  5. 翻译 *.po 文件
  6. 现在确保 conf.py 中的 locale_dirs = ['../locales'] 指向语言环境的目录! 我的默认设置不正确。我不得不将 dir 更改为 parent ( ../ ) 并使用“locales”而不是默认的“locale”来描述路径。
  7. 运行 sphinx-intl build 从 *.mo 文件创建二进制文件 (*.mo)。
  8. 将当前终端的语言设置为法语:set SPHINXOPTS=-D language=fr
  9. make html