Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Extract translatable strings from Handlebars templates.


latest commit 1002863c4b
Sam Hauglustaine smhg authored
Failed to load latest commit information.
bin color complete error msg
.gitignore handle project files
.jshintrc jshint config
.npmignore handle project files
.travis.yml remove grunt from travis
LICENSE github license template refer to list for language option (fixes #36)
index.js enable swig templates
xgettext-template.sublime-project handle project files

xgettext-template build status

Extracts translatable strings from source. Identical to xgettext(1) but for template languages.

tl;dr Get translatable strings from templates into Poedit.

Template language support

React's JSX and Jade are todos (PRs are much appreciated).

General workflow

In the following Handlebars example translatable content is passed to helpers (_ and ngettext):

<button>{{_ "Sign in"}}</button>

<p>{{count}} {{ngettext "country" "countries" count}}</p>

With Handlebars, this requires helpers being registered:

Handlebars.registerHelper('_', function(msgid) {
  return i18n.gettext(msgid);

Handlebars.registerHelper('ngettext', function(msgid, plural, count) {
  return i18n.ngettext(msgid, plural, count);

What this i18n object refers to is up to you. Some (client/server) options are:

xgettext-template parses the strings above out of your templates into gettext's PO files. These PO files are then translated and compiled to binary MO files using applications like Poedit. The MO files are passed as input the i18n library (above).


$ npm install -g xgettext-template


$ xgettext-template [OPTION] [INPUTFILE]...


  • -D|--directory add directory to list for input files search.
  • -o|--output write output to specified file (default: stdout).
  • -L|--language specifies the language of the input files (default: determine from file extension). Use the language's full name from the template language support list above.
  • --from-code encoding of input files (default: ascii).
  • -k|--keyword additional keyword to be looked for (default: _,gettext,ngettext:1,2).
  • --force-po write PO file even if empty (default: false).
  • --no-location don't add file and line references (default: false).

In Poedit

Go to File - Preferences... in Poedit and add a new parser in the Parsers tab:

Poedit parser configuration

Please note that in this Windows example you have to use xgettext-template.cmd. The .cmd extension should not be there on *nix platforms.


  • Clone repository and run npm install.
  • Run npm test to lint & test.


xgettext-template initial development was founded by Dijiwan.

Something went wrong with that request. Please try again.