Giter Club home page Giter Club logo

babel-jsxgettext's Introduction

babel-jsxgettext

NPM version build status Downloads js-standard-style

A tool like jsxgettext, but works for es6 + jsx that babel support.

I have a blog post explain my translation workflow in an Electron app with React + Babel.

Usage

$ npm install babel-jsxgettext --save-dev

API

var parser = require('babel-jsxgettext')

/**
 * The parser function
 * @param  {String}   input  The path to source JavaScript file
 * @param  {String}   output The path of the output PO file
 * @param  {String}   plugins Babel parser plugins, separate by `,`
 * @param  {Function} cb     The callback function
 */
parser(inputs, output, plugins, function (err) {
  if (err) throw err
  console.log('Job completed!')
})

Command line usage

Install globally with npm npm install babel-jsxgettext -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
    $ babel-jsxgettext --help
    $ babel-jsxgettext <input> <output>

  Examples
    $ babel-jsxgettext ./test/*.js ./test.po
    $ babel-jsxgettext --plugins "classProperties,objectRestSpread" ./test/*.js test.po

Why

I'm Using Babel with React + JSX for most of my project, but there's no perfect and direct way to generate .po file from ES6 + JSX code(or from a directory).

acron-jsx support jsx but not all the feature I use in Babel(ES7 etc.,). So I grab the Babel parser and use it to generate .po file.

License

MIT

babel-jsxgettext's People

Contributors

aaugustin avatar dsingleton avatar faxioman avatar fraserxu avatar frgtn avatar jeresig avatar yuri1992 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

babel-jsxgettext's Issues

Using babel plugins

there any way to let babel-jsxgettext get known about babel plugins ?

Input Code

class Form extends React.Component {

    static propTypes = {
        onFinish: React.PropTypes.func,
        notifyUser: React.PropTypes.func,
        canSubmit: React.PropTypes.func,
        onSubmit: React.PropTypes.func,
        paymentMethod: React.PropTypes.object
    };

Babel Configuration

{
  "presets": [
    "es2015",
    "react"
  ],
  "plugins": [
    "transform-class-properties"
  ]
}

Expected Behavior

parsing static class properties

Current Behavior

/home/yurir/Development/sef-new/node_modules/babel-jsxgettext/node_modules/babylon/lib/index.js:4376
  throw err;
  ^

SyntaxError: Unexpected token (11:21)
    at Parser.pp$5.raise (/home/yurir/Development/sef-new/node_modules/babel-jsxgettext/node_modules/babylon/lib/index.js:4373:13)
    at Parser.pp.unexpected (/home/yurir/Development/sef-new/node_modules/babel-jsxgettext/node_modules/babylon/lib/index.js:1716:8)
    at Parser.pp$1.parseClassProperty (/home/yurir/Development/sef-new/node_modules/babel-jsxgettext/node_modules/babylon/lib/index.js:2507:50)
    at Parser.pp$1.parseClassBody (/home/yurir/Development/sef-new/node_modules/babel-jsxgettext/node_modules/babylon/lib/index.js:2424:34)
    at Parser.pp$1.parseClass (/home/yurir/Development/sef-new/node_modules/babel-jsxgettext/node_modules/babylon/lib/index.js:2361:8)
    at Parser.pp$1.parseStatement (/home/yurir/Development/sef-new/node_modules/babel-jsxgettext/node_modules/babylon/lib/index.js:1798:19)
    at Parser.pp$1.parseBlockBody (/home/yurir/Development/sef-new/node_modules/babel-jsxgettext/node_modules/babylon/lib/index.js:2223:21)
    at Parser.pp$1.parseTopLevel (/home/yurir/Development/sef-new/node_modules/babel-jsxgettext/node_modules/babylon/lib/index.js:1733:8)
    at Parser.parse (/home/yurir/Development/sef-new/node_modules/babel-jsxgettext/node_modules/babylon/lib/index.js:1628:17)
    at Object.parse (/home/yurir/Development/sef-new/node_modules/babel-jsxgettext/node_modules/babylon/lib/index.js:7083:37)

Your Environment

software version
Babylon 6.16.1
node v7.2.1
npm [email protected]
Operating System archlinux

Extracts comments that begin with "L10n:"

Hi,
is there any option to extract comments like jsxgettext?
// L10n: Don't forget the exclamation mark
gettext("Hello world!"); // L10n: Salutation to the world

Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.