Skip to content

mkdocs-mdpo-plugin

Translations for Mkdocs using PO files, fully customizable. Compatible with mkdocs-material, based on mdpo.

Install

pip install mkdocs-mdpo-plugin

Usage

Enable the plugin in your mkdocs.yml:

plugins:
  - mdpo

Minimal configuration

With mkdocs-material

theme:
  name: material
  language: en

extra:
  alternate:
    - name: English
      lang: en
    - name: Español
      link: es
      lang: es

plugins:
  - mdpo

Standalone

plugins:
  - mdpo:
      languages:
        - en     # first language is the original
        - es

Both previous configurations will create the same layout of files building the documentation. Given the next layout in a docs/ directory:

docs
└── index.md

After the build, you will get:

docs
├── es
│   └── index.md.po
└── index.md

Just translate the strings in docs/es/index.md.po into Spanish, build again with mkdocs build and the site/ directory will look like:

site
├── 404.html
├── assets
│   ├── images
│   ├── javascripts
│   └── stylesheets
├── es
│   └── index.html
├── index.html
├── sitemap.xml
└── sitemap.xml.gz

How does it works

mkdocs-mdpo-plugin is based in mdpo which is a program to translate CommonMark compliant Markdown content using PO files.

As with mkdocs you write Python-Markdown's implementation of Markdown, mkdocs-mdpo-plugin uses the xml.etree.ElementTree to translate the rest messages of custom HTML created by the extensions. This is the reason why for some of them the translation process must be adjusted somewhat to be supported correctly (see Extensions support).

Known limitations

  • The command mkdocs serve doesn't work.
  • Currently, edited messages are not marked as fuzzy like xgtettext does.

Immprove the mkdocs-material's language selector

If you are using the mkdocs-material theme, you can install the mkdocs-material-relative-language-selector plugin to make relative links between languages inside the same page and remove the current displayed language from the language selector:

pip install mkdocs-material-relative-language-selector
plugins:
  - search
  - material-relative-language-selector
  - mdpo
plugins:
  - search
  - material-relative-language-selector:
      root_domain: true
  - mdpo

Projects using mkdocs-mdpo-plugin