This document explains how to work with translations in the Mapflow documentation.
source/
├── locale/
│ ├── en/ # English (source language)
│ │ └── LC_MESSAGES/
│ │ ├── *.po # English PO files (source text)
│ │ └── *.mo # Compiled message catalogs
│ ├── ru/ # Russian
│ │ └── LC_MESSAGES/
│ │ ├── *.po # Russian translations
│ │ └── *.mo # Compiled message catalogs
│ └── *.pot # Template files (auto-generated)
├── _templates/
│ └── language_selector.html # Language switcher dropdown
└── conf.py # Sphinx configuration with i18n settings
Extract translatable strings from RST files to POT template files:
make gettextOr manually:
sphinx-build -b gettext source source/localeUpdate PO files for all languages (merges new strings, marks outdated ones):
make update-poOr manually:
sphinx-intl update -p source/locale -l en
sphinx-intl update -p source/locale -l ruEdit the .po files in source/locale/[LANG]/LC_MESSAGES/ directories:
- English PO files (
source/locale/en/LC_MESSAGES/*.po) contain the source text - Translation PO files (e.g.,
source/locale/ru/LC_MESSAGES/*.po) need to be translated
Example PO file entry:
#: ../../source/userguides/imagery_search.rst:4
msgid "Imagery search"
msgstr "Поиск изображений"Build all language versions:
make build-allOr use the comprehensive build script:
./build_all_languages.shOr build specific languages:
# English
sphinx-build -b html source build/docs/en
# Russian
sphinx-build -b html -D language=ru source build/docs/ruTo add a new language (e.g., Spanish):
Add the language code to the languages list:
languages = ['en', 'ru', 'es'] # Added 'es' for SpanishAdd the language name to html_context:
html_context = {
'languages': [
('English', 'en'),
('Русский', 'ru'),
('Español', 'es'),
],
'current_language': language,
}sphinx-intl update -p source/locale -l esUpdate Makefile:
update-po: gettext
sphinx-intl update -p $(SOURCEDIR)/locale -l en
sphinx-intl update -p $(SOURCEDIR)/locale -l ru
sphinx-intl update -p $(SOURCEDIR)/locale -l es # Add this line
@echo "PO files updated."
build-all: update-po
@echo "Building English version..."
@$(SPHINXBUILD) -b html "$(SOURCEDIR)" "$(BUILDDIR)/docs/en" $(SPHINXOPTS)
@echo "Building Russian version..."
@$(SPHINXBUILD) -b html -D language=ru "$(SOURCEDIR)" "$(BUILDDIR)/docs/ru" $(SPHINXOPTS)
@echo "Building Spanish version..."
@$(SPHINXBUILD) -b html -D language=es "$(SOURCEDIR)" "$(BUILDDIR)/docs/es" $(SPHINXOPTS) # Add this
@echo "All language versions built successfully!"Update build_all_languages.sh:
# 3. Update Spanish PO files
echo "Step 3b: Updating Spanish PO files..."
sphinx-intl update -p source/locale -l es
# 4. Build Spanish documentation
echo "Step 6: Building Spanish documentation..."
sphinx-build -b html -D language=es source build/docs/esTranslate the content in source/locale/es/LC_MESSAGES/*.po files.
./build_all_languages.sh- Poedit - Cross-platform, user-friendly GUI
- GTranslator - GNOME translation editor
- Lokalize - KDE translation tool
- VS Code with extensions:
- "gettext" extension for .po file syntax highlighting
- "Translation Helper" for translation assistance
-
Developer updates RST files
# After editing RST files make gettext make update-po -
Translator receives updated PO files
- PO files contain new strings marked as
#, fuzzy - Old strings marked as
#~ msgid(obsolete)
- PO files contain new strings marked as
-
Translator edits PO files
- Translate new strings
- Review fuzzy strings
- Remove obsolete entries
-
Build and test
make build-all # Preview at build/docs/[LANG]/index.html -
Commit translations
git add source/locale/ git commit -m "Update [LANGUAGE] translations"
# TRANSLATOR COMMENT
#: source/file.rst:line_number
#, flags
msgid "Source text"
msgstr "Translated text"#, fuzzy- Translation needs review (auto-generated or uncertain)#, python-format- String contains Python formatting#~- Obsolete entry (not used anymore)
Preserve variables and formatting:
msgid "Welcome to {project} version {version}"
msgstr "Bienvenue dans {project} version {version}"Solution: Ensure MO files are compiled
sphinx-intl buildSolution: Re-extract messages
make gettext
make update-poSolution: Ensure UTF-8 encoding in PO files
"Content-Type: text/plain; charset=UTF-8\n"- Sphinx Internationalization
- sphinx-intl Documentation
- GNU gettext Manual
- PO File Format Specification
- Keep source text clear - Write clear English in RST files
- Use consistent terminology - Maintain a glossary for technical terms
- Preserve formatting - Keep RST directives and inline markup
- Test builds - Always test after translating
- Regular updates - Update translations when RST files change
- Version control - Commit PO files to track translation history
- Translator notes - Add comments for context:
# Translators: This refers to...
- DO NOT edit
.potfiles manually (they are auto-generated) - DO NOT edit
.mofiles (they are compiled from.pofiles) - DO commit
.pofiles to version control - DO exclude
.mofiles from git (add to.gitignore) - DO preserve RST markup in translations
- 🇬🇧 English (en) - Source language
- 🇷🇺 Russian (ru) - Active translation
To add more languages, follow the "Adding a New Language" section above.