Перевод документации с помощью Sphinx

Sphinx — это инструмент для создания красивой документации. Он использует простой синтаксис reStructuredText и может генерировать вывод во многих форматах. Если вы ищете пример, то эта документация также собирается с его помощью. Очень полезным спутником при использовании Sphinx является сервис Read the Docs, который бесплатно будет собирать и публиковать вашу документацию.

I will not focus on writing documentation itself, if you need guidance with that, just follow instructions on the Sphinx website. Once you have documentation ready, translating it is quite easy as Sphinx comes with support for this and it is quite nicely covered in their Локализация. It’s matter of a few configuration directives and invoking the sphinx-intl tool.

If you are using Read the Docs service, you can start building translated documentation on Read the Docs. Their Localization and Internationalization covers pretty much everything you need - creating another project, setting its language, and linking it from the main project as a translation.

Now all you need is translating the documentation content. Sphinx generates PO file for each directory or top-level file, which can lead to quite a lot of files to translate (depending on gettext_compact settings). You can import the index.po into Weblate as an initial component and then configure Обнаружение компонентов add-on to automatically discover all others.

Настройки компонента

Название компонента

Documentation

Маска файла

docs/locales/*/LC_MESSAGES/index.po

Шаблон для новых переводов

docs/locales/index.pot

Формат файла

PO-файл gettext

Флаги перевода

rst-text

Настройка обнаружения компонентов

Регулярное выражение для сопоставления с файлами перевода

docs/locales/(?P<language>[^/.]*)/LC_MESSAGES/(?P<component>[^/]*)\.po

Настроить название компонента

Documentation: {{ component|title }}

Задать базовый файл для нового перевода

docs/locales/{{ component }}.pot

Подсказка

Вы хотите чтобы Sphinx создавал только один PO-файл? Начиная со Sphinx 3.3.0 это можно сделать с помощью:

gettext_compact = "docs"

Вот список некоторых проектов, которые используют этот подход для перевода документации: