Markdown files translator using PO files as reference.

mdpo.po2md.__init__.pofile_to_markdown(filepath_or_content, pofiles, ignore=[], save=None, md_encoding='utf-8', po_encoding=None, command_aliases={}, wrapwidth=80, events={}, debug=False, **kwargs)

Translate Markdown content or file using PO files as reference.

This implementation reproduces the same valid Markdown output, given the provided AST, with replaced translations, but doesn’t rebuilds the same input format as Markdown is just a subset of HTML.

  • filepath_or_content (str) – Markdown filepath or content to translate.

  • pofiles (str, list) – from where to extract messages to make the replacements translating strings.

  • ignore (list) – Paths of pofiles to ignore. Useful when a glob does not fit your requirements indicating the files to extract content. Also, filename or a dirname can be defined without indicate the full path.

  • save (str) – Saves the output content in file whose path is specified at this parameter.

  • md_encoding (str) – Markdown content encoding.

  • po_encoding (str) – PO files encoding. If you need different encodings for each file, you must define it in the “Content-Type” field of each PO file metadata, in the form "Content-Type: text/plain; charset=<ENCODING>\n".

  • command_aliases (dict) – Mapping of aliases to use custom mdpo command names in comments. The mdpo- prefix in command names resolution is optional. For example, if you want to use <!-- mdpo-on --> instead of <!-- mdpo-enable -->, you can pass the dictionaries {"mdpo-on": "mdpo-enable"} or {"mdpo-on": "enable"} to this parameter.

  • wrapwidth (int) – Maximum width used rendering the Markdown output.

  • events (dict) –

    Preprocessing events executed during the translation process. You can use these to customize the output. Takes functions are values. If one of these functions returns False, that part of the translation process is skipped by po2md. The available events are:

    • enter_block(self, block, details): Executed when the parsing a Markdown block starts.

    • leave_block(self, block, details): Executed when the parsing a Markdown block ends.

    • enter_span(self, span, details): Executed when the parsing of a Markdown span starts.

    • leave_span(self, span, details): Executed when the parsing of a Markdown span ends.

    • text(self, block, text): Executed when the parsing of text starts.

    • command(self, mdpo_command, comment, original command): Executed when a mdpo HTML command is found.

    • msgid(self, msgid, msgstr, msgctxt, tcomment, flags): Executed when a msgid is going to be replaced.

    • link_reference(self, target, href, title): Executed when each reference link is being written in the output (at the end of the translation process).

  • debug (bool) – Add events displaying all parsed elements in the translation process.


Markdown output file with translated content.

Return type