0.6.11 • Published 6 years ago
@vslutov/jsxgettext-stream v0.6.11
@vslutov/jsxgettext-stream
A tool like jsxgettext, but works for es6 + jsx that babel support.
Fork of fraserxu/babel-jsxgettext. Improvements:
- Interface is compatible with gnu xgettext
- Gulp stream support
Usage
$ npm install @vslutov/jsxgettext-stream --save-devGulp usage
const xgettext = require("@vslutov/jsxgettext-stream")
const poConcat = require("gulp-po-concat")
gulp.task('i18n:pot', () =>
  gulp.src(['src/**/*.js', 'src/**/*.jsx'])
    .pipe(xgettext({plugins: ['flow', 'objectRestSpread']}))
    .pipe(poConcat({domain: 'messages'}))
    .pipe(gulp.dest('src/i18n'))
)Program API
var parser = require('@vslutov/jsxgettext-stream/parser')
/**
 * The parser function
 * @param  {String}   input  The path to source JavaScript file
 * @param  {String}   plugins Babel parser plugins, separate by `,`
 * @param  {Function} cb     The callback function
 */
const main = async () {
  inputs = input_fnames.map(path => ({ path, contents: fs.readFileSync(path) }))
  const po_contents = await parser(inputs, [])
}Command line usage
Install globally with npm npm install @vslutov/jsxgettext-stream -g
  A tool like jsxgettext, but works for es6 + jsx that babel support
  Options
    --help                     Show this help
    --version                  Current version of package
    -p | --plugins             String - Babel parser plugins list (`jsx` is always included)'
    -i | --input               String - The path to soure JavaScript file
    -o | --output              String - The path of the output PO file
  Usage
    $ jsxgettext-stream --help
    $ jsxgettext-stream <input> <output>
  Examples
    $ jsxgettext-stream ./test/*.js ./test.po
    $ jsxgettext-stream --plugins "classProperties,objectRestSpread" ./test/*.js test.poLicense
MIT