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 if you store the PO files inside the documentation folder. Use another layout like the explained in locale_dir configuration.
  • Currently, edited messages are not marked as fuzzy like xgtettext does.

Projects using mkdocs-mdpo-plugin