Gettext implementation in JavaScript for markdown documents

Usage no npm install needed!

<script type="module">
  import gettextMarkdown from '';


gettext-markdown NPM version

A Gettext implementation in JavaScript for Markdown document



% npm install gettext-markdown

Getting Started with CLI

Generate POT from the markdown

$ gettext-md -o /path/to/__name__.pot --pot /path/to/

__name__ will be replaced with markdown for the above case.

Generate the localized markdown from translations

$ gettext-md -o /path/to/markdown/ --md /path/to/po/dirs

/path/to/po/dirs contains the gettext PO format files. __lang__ will be replaced with the certain language name according to PO files.

If you doubt, try

$ gettext-md -v /path/to/

This mode will validates if this library is capable to process the markdown properly. if it fails, please feel free to report it according to the instructions.

Getting Started with the code

How to generate POT

const gmd = require('gettext-markdown');

let pot = gmd.md2pot('/path/to/');

md2pot returns the POT file contents.

How to generate the localized markdown

const gmd = require('gettext-markdown');
const fs = require('fs');

let po = fs.readFileSync('/path/to/gettext.po', 'utf-8');
gmd.po2md('/path/to/gettext.po', po)
  .then((r) => {
    for (let i in r) {
      let filename = r[i].fn;
      let pofilename = r[i].po;
      let lang = r[i].lang;
      let data = r[i].data;
      // fn contains the original markdown file name
      // po contains the PO file name
      // lang contains the language name for this PO
      // data contains the localized markdown contents
  .catch((e) => console.error(e));

How to validate the markdown

const gmd = require('gettext-markdown');

  .then((resolve) => {
    // always returns true if it works
  }, (reject) => {
    // throw reject


Copyright (c) 2016 Akira TAGOH Licensed under the MIT license.

Project created by Akira TAGOH.