xgettext-webird v0.1.1
xgettext-webird 
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
- Handlebars (using gettext-handlebars)
- Swig (using gettext-swig)
- Volt (using gettext-volt)
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-webird 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).
Installation
$ npm install -g xgettext-webirdUsage
$ xgettext-webird [OPTION] [INPUTFILE]...Options
-D|--directoryadd directory to list for input files search.-o|--outputwrite output to specified file (default: stdout).-L|--languagespecifies 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-codeencoding of input files (default:ascii).-k|--keywordadditional keyword to be looked for (default:_,gettext,ngettext:1,2).--force-powrite PO file even if empty (default:false).--no-locationdon'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:
- Nunjucks
- Language:
Nunjucks - List of extensions...:
*.nunj - Parser Command:
xgettext-webird -L Swig --force-po -o %o %C %K %F - An item in keywords list:
-k %k - An item in input files list:
%f - Source code charset:
--from-code=%c
- Language:
- Volt
- Language:
Volt - List of extensions...:
*.volt - Parser Command:
xgettext-webird -L Volt --force-po -o %o %C %K %F - An item in keywords list:
-k %k - An item in input files list:
%f - Source code charset:
--from-code=%c
- Language:
Please note that in this Windows example you have to use xgettext-webird.cmd. The .cmd extension should not be there on *nix platforms.
Development
- Clone repository and run
npm install. - Run
npm testto lint & test.
Note
xgettext-template initial development was founded by Dijiwan. This xgettext-webird project is a fork of xgettext-template.