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

发布于 2025-01-14 10:12:47 字数 2694 浏览 3 评论 0原文

在遵循官方翻译文件工作流程后,我发现我自己就处于翻译似乎不起作用的情况下。

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

我已成功创建 *.pot 和 *.po 文件,并测试翻译了此 *.po 文件的部分(其他 msgid 仍默认为“”。然后我将语言设置为法语并运行 make 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 文件。

After following the official workflow for translating files I find myself in a situation where the translation doesn't seem to work.

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

I have successfully created *.pot and *.po files and testwise translated parts of this *.po-file (other msgid's still default to "". Then I set the language to french and run make html again - but the text that I translated isn't displayed in french.

Nothing in the build output shows any hint on what's wrong:

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.

Note that I excluded warnings that have to do with silly syntax mistakes I made in one of the files (the one I'm currently working on).

Is this expected behaviour or am I doing something wrong? I wanted to test the translation functionality and my *.po files.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

路还长,别太狂 2025-01-21 10:12:47

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

回溯正确工作的步骤:

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

I found the solution. Sphinx didn't actually pick up on the .mo (binary) files.

Steps to retrace for correct working:

  1. Make sure you're in root directory and you see build and source directories
  2. Using sphinx gettext will create *.pot files in build/gettext
  3. Take those *.pot files and translate to *.po files using sphinx-intl update -p build/gettext -l fr (example for french/'fr'). This will create *.po files in a new folder locales which by default sits amongst the build and source dirs under root.
  4. Translate *.po files
  5. Now make sure that locale_dirs = ['../locales'] in conf.py points to the directory of the locales! This was not set up properly by default in my case. I had to change dir to parent ( ../ ) and use "locales" instead of the default "locale" to describe the path.
  6. Run sphinx-intl build to create binaries (*.mo) out of *.mo files.
  7. Set language to french for current terminal: set SPHINXOPTS=-D language=fr
  8. make html
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文