Technical implementation of translation¶
This page documents the code involved in translating files. It is only necessary to read this page if you are editing or debugging these technical processes. Otherwise, the steps have been simplified and abstracted into the two commands make extract and make, covered under Technical processes for translation and Building the documentation.
Note
We use the gettext system for translation. In gettext, strings to translate are referred to as ‘messages’, and messages are collected into ‘domains’, which correspond to POT files.
Extract messages¶
First, strings to translate are extracted from files with make extract.
Extract from Codelist CSV files and JSON Schema files¶
make extract builds the
extract_codelistsandextract_schemaMake targets, among others. These run:pybabel extract -F babel_ocds_codelist.cfg . -o $(POT_DIR)/$(DOMAIN_PREFIX)codelists.pot pybabel extract -F babel_ocds_schema.cfg . -o $(POT_DIR)/$(DOMAIN_PREFIX)schema.pot
pybabel extract extracts messages from source files and generates a POT file. The
-F(--mapping-file) option sets the path to the Babel mapping configuration file,babel_ocds_codelist.cfgorbabel_ocds_schema.cfg.The Babel mapping configuration files,
babel_ocds_codelist.cfgandbabel_ocds_schema.cfg, map Babel message extraction method names –ocds_codelistandocds_schema– to the codelist CSV and JSON Schema source files from which to extract strings to translate.pyproject.toml in ocds-babel maps the Babel message extraction method names –
ocds_codelistandocds_schema– to the module and function implementing the extraction, in the entry point groupbabel.extractors.The functions extract_codelist and extract_schema implement the extraction.
Extract from Markdown files¶
make extractbuilds theextract_markdownMake target, among others. This runs:sphinx-build -q -b gettext $(DOCS_DIR) $(POT_DIR)
See the Sphinx documentation.
Translate source files¶
After pushing strings to translate as POT files to a translation tool, translating the strings, and pulling translations as PO files from a translation tool, source files are translated with make.
Translate Codelist CSV files and JSON Schema files¶
make builds the
compileMake target. This compiles to MO files the PO files for codelist CSV files and JSON Schema files.pybabel compile --use-fuzzy -d $(LOCALE_DIR) -D $(DOMAIN_PREFIX)schema pybabel compile --use-fuzzy -d $(LOCALE_DIR) -D $(DOMAIN_PREFIX)codelists
makethen buildsbuild.*Make targets, among others. These run, for example:sphinx-build -q -b dirhtml $(DOCS_DIR) $(BUILD_DIR)/es -D language="es"
sphinx-build, when
languageis set, compiles to MO files the PO files for Markdown files, which can also be done by runningsphinx-intl build -d $(LOCALE_DIR).sphinx-build runs
setupinconf.py, which reads thelanguageoverride (-D language="es").setup in conf.py calls the translate method to translate codelist CSV files and JSON Schema files from one directory into another directory, using MO files.
The translated files are used by Sphinx directives like
csv-table-no-translateandjsonschemain Markdown files.
Translate Markdown files¶
makebuilds thebuild.*Make targets, among others. These run, for example:sphinx-build -q -b dirhtml $(DOCS_DIR) $(BUILD_DIR)/es -D language="es"
See the Sphinx documentation.
Please correct all warnings, ignoring WARNING: inconsistent term references in translated message.