Giter VIP home page Giter VIP logo

jsxgettext's Introduction

jsxgettext Build Status NPM version

A node module with a CLI that extracts gettext strings from JavaScript, EJS, Jade, Jinja, Swig and Handlebars files. Uses a real parser, acorn, for JavaScript files and recognizes the following uses:

gettext("Hello world!");
gettext("Hello " + 'world!');
myModule.gettext("Hello " + 'world!');
gettext.call(myObj, "Hello " + 'world!');
ngettext("Here's an apple for you", "Here are %s apples for you", 3);
ngettext("Here's an apple" + ' for you', "Here are %s apples" + ' for you', 3);
myModule.ngettext("Here's an apple" + ' for you', "Here are %s apples" + ' for you', 3);
ngettext.call(myObj, "Here's an apple" + ' for you', "Here are %s apples" + ' for you', 3);

It also extracts comments that begin with "L10n:" when they appear above or next to a gettext call:

// L10n: Don't forget the exclamation mark
gettext("Hello world!");  // L10n: Salutation to the world

"L10n:" is a default value and you can change it with -c option.

Install

npm install jsxgettext

Or from source:

git clone https://github.com/zaach/jsxgettext.git
cd jsxgettext
npm link

Use

$ jsxgettext -h


Usage: cli [options] [file ...]

Options:

  -h, --help                         output usage information
  -V, --version                      output the version number
  -o, --output <file>                write output to specified <file>
  -p, --output-dir <path>            output files will be placed in directory <path>
  -k, --keyword [keywords]           additional keywords to be looked for
  -j, --join-existing                join messages with existing file
  -L, --language [lang]              use the specified language (javascript, ejs, jinja, handlebars, jade, swig) [javascript]
  -s, --sanity                       sanity check during the extraction
  --project-id-version [version]     This is the project name and version of the generated package/catalog.
  --report-bugs-to [bug address]     An email address or URL where you can report bugs in the untranslated strings.
  -c, --add-comments [tag]           place comment blocks starting with TAG and preceding keyword lines in output file (default: "L10n:").
  --parser-options [parser options]  A json to customize acorn parser.

jsxgettext's People

Contributors

andris9 avatar arthraim avatar beck avatar byk avatar clkao avatar cruzdanilo avatar eddvdm avatar faergeek avatar fmarier avatar jacobrask avatar justinvdm avatar kaareal avatar lloyd avatar mahata avatar mphasize avatar mweibel avatar nigelzor avatar ozten avatar pirxpilot avatar rfk avatar ruscoder avatar stevebartholomew avatar swatinem avatar tagoh avatar vladikoff avatar vrouet avatar zaach avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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  avatar  avatar  avatar  avatar

jsxgettext's Issues

async/await

Hi,
is it possible to add async/await support?

Domain and context function

It's great that plurals were finally implemented.

I believe there left only one crucial piece, without which most projects will suffer: domain or context.

Those are:

// domain
dgettext    = function ( domain, key )
dngettext   = function ( domain, singular_ley, plural_key, value )

// or context
pgettext    = function ( context, key )
npgettext   = function ( context, singular_key, plural_key, value )

// or both
dpgettext   = function ( domain, context, key )
dnpgettext  = function ( domain, context, singular_key, plural_key, value )

// or with category
dcgettext   = function ( domain, key, category )
dcngettext  = function ( domain, singular_key, plural_key, value, category )
dcnpgettext = function ( domain, context, singular_key, plural_key, value, category )

I'm not sure about category. Don't remember I've seen it used somewhere, since usually it's enough to have just context.

Domains (which are, in fact, language codes) aren't interesting for us during extraction, but crucial for output. So, in case of domain jsxgettext should be able to simply skip it.

So, I'd say, it's crucial to have at least context and domains, since without domains it's impossible for devs to load string from specific domain, and without context it's impossible to implement context-aware strings and feminine forms.

Edited: sorry, there were error in domains description. I always forgetting that they are in fact languages, into which string should be outputted)

support multiple keywords

Calling it with jsxgettext --keyword=t --keyword=_ only applies the second keyword _, not the first one.

PR coming later today.

Second HTML Attribute cannot have EJS code

The following blows up the EJS parser:

<html lang="<%= lang %>" dir="<%= lang_dir %>">
<%= _('hey') %>
</html>

If I remove <%= lang_dir %> then it will parse fine.

Example:

../node_modules/.bin/jsxgettext -L EJS --keyword=_ --output-dir=../locale/templates/LC_MESSAGES --output=messages.pot t.ejs

node.js:201
        throw e; // process.nextTick error, or 'error' event on first tick
              ^
Error: Line 1: Unexpected identifier
    at throwError (/home/ozten/bigtent/node_modules/jsxgettext/node_modules/esprima/esprima.js:1151:21)
    at throwUnexpected (/home/ozten/bigtent/node_modules/jsxgettext/node_modules/esprima/esprima.js:1197:13)
    at consumeSemicolon (/home/ozten/bigtent/node_modules/jsxgettext/node_modules/esprima/esprima.js:1292:13)
    at parseStatement (/home/ozten/bigtent/node_modules/jsxgettext/node_modules/esprima/esprima.js:2791:9)
    at /home/ozten/bigtent/node_modules/jsxgettext/node_modules/esprima/esprima.js:3295:38
    at parseSourceElement (/home/ozten/bigtent/node_modules/jsxgettext/node_modules/esprima/esprima.js:3030:20)
    at parseSourceElements (/home/ozten/bigtent/node_modules/jsxgettext/node_modules/esprima/esprima.js:3063:29)
    at parseProgram (/home/ozten/bigtent/node_modules/jsxgettext/node_modules/esprima/esprima.js:3077:19)
    at /home/ozten/bigtent/node_modules/jsxgettext/node_modules/esprima/esprima.js:3295:38
    at Object.parse (/home/ozten/bigtent/node_modules/jsxgettext/node_modules/esprima/esprima.js:3551:23)

Include filename in throw

var ast      = parser.parse(source, {
  ecmaVersion: 6,
  locations: true
});
} catch(e) {

    e.fileName = filename;
    throw e;
};

Running on javascript files with anonymous functions?

Hi,

Maybe I'm wrong, but why compiling :

(function () {
  //foobar;
  var x = gettext('pizza');
})();

results in :

/Users/abernier/Sites/upup-www/node_modules/jsxgettext/lib/jsxgettext.js:35
            typeof node.arguments[0].value === 'string')  // must have a strin
                                    ^
TypeError: Cannot read property 'value' of undefined
    at checkExpr (/Users/abernier/Sites/upup-www/node_modules/jsxgettext/lib/jsxgettext.js:35:37)
    at Controller.traverse.enter (/Users/abernier/Sites/upup-www/node_modules/jsxgettext/lib/jsxgettext.js:50:13)
    at Controller.__execute (/Users/abernier/Sites/upup-www/node_modules/jsxgettext/node_modules/estraverse/estraverse.js:238:31)
    at traverse (/Users/abernier/Sites/upup-www/node_modules/jsxgettext/node_modules/estraverse/estraverse.js:305:34)
    at /Users/abernier/Sites/upup-www/node_modules/jsxgettext/lib/jsxgettext.js:47:5
    at Array.forEach (native)
    at Object.gen [as generate] (/Users/abernier/Sites/upup-www/node_modules/jsxgettext/lib/jsxgettext.js:43:24)
    at gen (/Users/abernier/Sites/upup-www/node_modules/jsxgettext/lib/cli.js:78:25)
    at main (/Users/abernier/Sites/upup-www/node_modules/jsxgettext/lib/cli.js:69:5)
    at Object.<anonymous> (/Users/abernier/Sites/upup-www/node_modules/jsxgettext/lib/cli.js:87:1)

I thought I could have used jsxgettext to extract gettext's keys from my compiled dust templates (since it's just javascript functions), but this issue cast doubt on this...

A compiled dust template looks like this:

(function(){
    dust.register("box.html",body_0);

    function body_0(chk,ctx){
        return chk.write("<h1>").reference(ctx.getPath(false,["box","name"]),ctx,"h").write("</h1>");
    }
return body_0;})();

Can you enlighten me?

Thank you

handlebars trans func tag not detected when in another block tag

For the content below the translation does not work
jsxgettext -s -L handlebars -k trans NewActivityNotification.html

{{#subject}} 
{{ trans "Activity in the project" }} 
{{/subject}}

It seems that the cause is the following:
when parseHandlebars is called recursively, it is called with escaped quotes in string.
parseHandlebars src param is
{{ trans \"Activity in the project\" }}

temporary workaround is to add space after blocktag name - i.e. {{#subject }} ... {{/subject }}, but it's fragile - too easy to overlook.

JSX bare attributes throw exception

When I run jsxgettext on the following JS(X) snippet:

const x = <input required/>;

I get an exception:

jsxgettext/lib/jsxgettext.js:29
    if (node.value.type === 'JSXExpressionContainer') {
                  ^

TypeError: Cannot read property 'type' of null
    at Object.assign.JSXAttribute (jsxgettext/lib/jsxgettext.js:29:19)
    at c (jsxgettext/node_modules/acorn/dist/walk.js:38:15)

Changing the bare attribute to required={true} fixes the error.

Support for ngettext

@BYK Was wondering if you have plans to support ngettext (and possibly dgettext and its other friends)?

Support custom function names

Some projects uses another gettext function names, like, _t() for singular forms and _pt() for plurals, etc.

Is there any chances to see ability pass to jsxgettext object which will map custom function names to gettext(), ngettext() and so on?

grunt-xgettext partially implemented that feature, maybe something can be learned from it. Besides, there were issue about even further expending of that feature: https://github.com/arendjr/grunt-xgettext/issues/8

Custom data attribute throws error

I'm using i18n.abide which uses jsxgettext.

Given this snipped

´´´
title=gettext("Share on Twitter")
´´´
works

´´´
title=gettext("Share on Twitter"), data-text= gettext("Have a look at this")
´´´

leads to

´´´
/node_modules/i18n-abide/node_modules/jsxgettext/node_modules/esprima/esprima.js:3871
throw e;
^
Error: Line 28: Unexpected identifier
´´´

Bad Message ID block merge

gettext("Hello world");
ngettext("Hello world","Hello worlds", 2);

Will give the following instead of two separate message id blocks.

: /home/andrew/igaro/git/app/src/app/cdn/js/route.main.js:33

: /home/andrew/igaro/git/app/src/app/cdn/js/route.main.js:34

msgid "Hello world"
msgstr ""

TypeError: Cannot read property '1' of undefined

Steps to Reproduce

  1. Create a sample project and npm install [email protected]

  2. test.js with

// The "gettext" function here is only used for static analysis.                                                                               
var templates = {
  "pin_verification": {
      landing: 'pin_verification',
    subject: gettext("Confirm email address for Persona")
  }
};
  1. ./jsxgettext/lib/jsxgettext.js test.js

Expected

No output, everything is fine

Actual

/home/ozten/bigtent/node_modules/i18n-abide/node_modules/jsxgettext/lib/jsxgettext.js:52
      return source.slice(0, range[1]).split('\n').length;
                                  ^
TypeError: Cannot read property '1' of undefined
    at lineFromRange (/home/ozten/bigtent/node_modules/i18n-abide/node_modules/jsxgettext/lib/jsxgettext.js:52:35)
    at /home/ozten/bigtent/node_modules/i18n-abide/node_modules/jsxgettext/lib/jsxgettext.js:60:27
    at Array.forEach (native)
    at findComments (/home/ozten/bigtent/node_modules/i18n-abide/node_modules/jsxgettext/lib/jsxgettext.js:58:16)
    at Controller.Object.keys.forEach.traverse.enter (/home/ozten/bigtent/node_modules/i18n-abide/node_modules/jsxgettext/lib/jsxgettext.js:40:26)
    at Controller.__execute (/home/ozten/bigtent/node_modules/i18n-abide/node_modules/jsxgettext/node_modules/estraverse/estraverse.js:238:31)
    at traverse (/home/ozten/bigtent/node_modules/i18n-abide/node_modules/jsxgettext/node_modules/estraverse/estraverse.js:305:34)
    at /home/ozten/bigtent/node_modules/i18n-abide/node_modules/jsxgettext/lib/jsxgettext.js:30:5
    at Array.forEach (native)
    at Object.gen [as generate] (/home/ozten/bigtent/node_modules/i18n-abide/node_modules/jsxgettext/lib/jsxgettext.js:26:24)

improve api to allow access to parsers without going over the cli

It would nice if i could get access the parsers a different way than this.

var jsxgettext = require('jsxgettext');
var parsers  = require('./../../node_modules/jsxgettext/lib/parsers/index'); //not very nice
var result = jsxgettext.generate.apply(jsxgettext, parsers.jade(sources, opt));

Improving the api would make it easier to use in other plugins

Support for msgmerge like functionality or otherwise enable smarter merging.

Default PO generation will overwrite existing translations with empty strings.

Using --join-existing flag leads to stale contextual comments and code references that clutter the PO file - which leads to either confusion on translator end or additional manual maintenance of the PO files.

Default solution is to incorporate another step and use msgmerge program from the Gettext utilities, however I find that slightly inconvenient and unnecessary while working on pure JS projects.

Are there any plans to improve on this behaviour?

I am also open to contributing a PR for this if you can give me some guidelines.

Fails on comments in js file

//foobar;
var x = gettext('pizza');

fails with this

TypeError: Cannot read property '1' of undefined
    at lineFromRange (/Users/kaareal/Code/closeterie/node_modules/jsxgettext/lib/jsxgettext.js:52:35)
    at /Users/kaareal/Code/closeterie/node_modules/jsxgettext/lib/jsxgettext.js:59:27
    at Array.forEach (native)
    at findComments (/Users/kaareal/Code/closeterie/node_modules/jsxgettext/lib/jsxgettext.js:58:16)
    at Controller.Object.keys.forEach.traverse.enter (/Users/kaareal/Code/closeterie/node_modules/jsxgettext/lib/jsxgettext.js:43:26)
    at Controller.__execute (/Users/kaareal/Code/closeterie/node_modules/jsxgettext/node_modules/estraverse/estraverse.js:238:31)
    at traverse (/Users/kaareal/Code/closeterie/node_modules/jsxgettext/node_modules/estraverse/estraverse.js:305:34)
    at /Users/kaareal/Code/closeterie/node_modules/jsxgettext/lib/jsxgettext.js:33:5
    at Array.forEach (native)
    at Object.gen [as generate] (/Users/kaareal/Code/closeterie/node_modules/jsxgettext/lib/jsxgettext.js:29:24)

UTF-8 Charset

pocompiler doesn't set "charset=utf-8" in the Content-Type header.

Support standard way of translator comments

@mphasize reported that the standard way of adding translator comments is using triple slashes:

/// Note to translators: you are awesome
gettext('Hello world');

We should probably support that syntax in addition to our custom // L10n: format.

Multiple escaped double-quotes

If you run jsxgettext on a file with something that contains double-quotes in a localized string and uses join-existing. The .pot output gets escaped more and more with each run.

I'm going to try and provide a failing test as an example. So far running via generate doesn't seem to repro.

jsxgettext doesn't work with recent versions of escodegen anymore

Trying to run jsxgettext with escodegen 0.0.20, I get this:

My Path is  /home/francois/devel/abide-demo/node_modules/i18n-abide/bin/home/francois/devel/abide-demo/node_modules/i18n-abide/node_modules/.bin/jsxgettext


/home/francois/devel/abide-demo/node_modules/i18n-abide/node_modules/jsxgettext/lib/jsxgettext.js:31
    traverse(ast, {
    ^
TypeError: undefined is not a function
    at /home/francois/devel/abide-demo/node_modules/i18n-abide/node_modules/jsxgettext/lib/jsxgettext.js:31:5
    at Array.forEach (native)
    at Object.gen [as generate] (/home/francois/devel/abide-demo/node_modules/i18n-abide/node_modules/jsxgettext/lib/jsxgettext.js:27:24)
    at gen (/home/francois/devel/abide-demo/node_modules/i18n-abide/node_modules/jsxgettext/lib/cli.js:78:25)
    at main (/home/francois/devel/abide-demo/node_modules/i18n-abide/node_modules/jsxgettext/lib/cli.js:69:5)
    at Object.<anonymous> (/home/francois/devel/abide-demo/node_modules/i18n-abide/node_modules/jsxgettext/lib/cli.js:87:1)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)

Which is due to the fact that traverse was removed in escodegen 0.0.16.

Issues parsing JavaScript

Running jsxgettext against JavaScript code under https://github.com/mozilla/browserid-bigtent blows up on the following files:

server/tests/passthrough_proxy.js
server/tests/http_proxy.js
server/tests/mock_proxy_idp.js

Example:

../node_modules/.bin/jsxgettext -L JS --keyword=_ --output-dir=../locale/templates/LC_MESSAGES --output=messages.pot ../server/tests/http_proxy.js

node.js:201
        throw e; // process.nextTick error, or 'error' event on first tick
              ^
Error: Line 1: Unexpected token ILLEGAL
    at throwError (/home/ozten/bigtent/node_modules/jsxgettext/node_modules/esprima/esprima.js:1156:21)
    at Object.advance (/home/ozten/bigtent/node_modules/jsxgettext/node_modules/esprima/esprima.js:1084:9)
    at collectToken (/home/ozten/bigtent/node_modules/jsxgettext/node_modules/esprima/esprima.js:3196:27)
    at lookahead (/home/ozten/bigtent/node_modules/jsxgettext/node_modules/esprima/esprima.js:1113:18)
    at parseSourceElements (/home/ozten/bigtent/node_modules/jsxgettext/node_modules/esprima/esprima.js:3038:21)
    at parseProgram (/home/ozten/bigtent/node_modules/jsxgettext/node_modules/esprima/esprima.js:3077:19)
    at /home/ozten/bigtent/node_modules/jsxgettext/node_modules/esprima/esprima.js:3295:38
    at Object.parse (/home/ozten/bigtent/node_modules/jsxgettext/node_modules/esprima/esprima.js:3551:23)
    at /home/ozten/bigtent/node_modules/jsxgettext/lib/jsxgettext.js:27:25
    at Array.forEach (native)

Extraction from jade templates, mixins don't work

As the title says, extraction doesn't work when the translated string is a parameter of a mixin.
I've hacked around a bit and found that there's a token type "call" that isn't handled in parsers/jade.js.
I got it to work by simply adding this:

      case 'call':
        append.call(token, extractGettext(token.args));
      break;

My tests look very promising but it seems a bit too straightforward.
Should I submit a PR? Anything else I can do?

Support ES6 template tags

ES6 has template tags like this:

gettext`Some translatable string with ${variable} replacement`

We'd better support this.

concatenated strings are not extracted

jsxgettext does not extract strings that are concatenated with the plus concatenation operator.

A javascript file contains the following:

gettext("This is the first string");

gettext(
    "The second string is significantly longer "+
    "and we'd like to concatenate it in our source "+
    "code to avoid really wide files."
);

Running jsxgettext on this file nets you:

# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2012-06-24 09:50+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"

#: test_jsxgettext.js:1
msgid "This is the first string"
msgstr ""

The second string is not in the po file.

What should happen is an additional entry in the po file that looks like this:

#: test_jsxgettext.js:3
msgid ""
"The second string is significantly longer and we'd like to concatenate it in "
"our source code to avoid really wide files."
msgstr ""

Using node v0.6.18
and jsxgettext v0.0.4

Is it alive?

There seems to be no updates for quite a while. Just wondering, is that project still maintained?

Reproducable releases

Currently, we use >= in package.json.

jsxgettext should produce releases with fixed version numbers in dependencies, so that production systems that use jsxgettext can have reproducible builds.

Support Jade

Its kind of hard to avoid http://jade-lang.com/ these days, if you are running an updated version of the express framework for node.

It would be great to have support for it.

support for ES6 / JSX

Would love to have strings extracted out from an ES6 / JSX file like this:

import React, { PropTypes, Component } from "react";
import JoinForm from "../../components/auth/join-form";

class JoinPage extends Component {
  static propTypes = {
    status: PropTypes.string,
    user: PropTypes.object
  }

  render() {
    var msg = gettext("Hello world")

    return (
      <div>
        <JoinForm {...this.props} />
      </div>
    );
  }
}

export default JoinPage;

at the moment trying to do jsxgettext on this file spits on the following error:

/Users/shawnlim/Documents/Code/reactjs/boa/node_modules/jsxgettext/node_modules/acorn/acorn.js:335
    throw err;
          ^
SyntaxError: Unexpected token (7:19)
    at raise (/Users/shawnlim/Documents/Code/reactjs/boa/node_modules/jsxgettext/node_modules/acorn/acorn.js:333:15)
    at unexpected (/Users/shawnlim/Documents/Code/reactjs/boa/node_modules/jsxgettext/node_modules/acorn/acorn.js:1366:5)
    at expect (/Users/shawnlim/Documents/Code/reactjs/boa/node_modules/jsxgettext/node_modules/acorn/acorn.js:1360:18)
    at parseFunctionParams (/Users/shawnlim/Documents/Code/reactjs/boa/node_modules/jsxgettext/node_modules/acorn/acorn.js:2335:5)
    at parseMethod (/Users/shawnlim/Documents/Code/reactjs/boa/node_modules/jsxgettext/node_modules/acorn/acorn.js:2286:5)
    at parseClass (/Users/shawnlim/Documents/Code/reactjs/boa/node_modules/jsxgettext/node_modules/acorn/acorn.js:2425:22)
    at parseStatement (/Users/shawnlim/Documents/Code/reactjs/boa/node_modules/jsxgettext/node_modules/acorn/acorn.js:1563:25)
    at parseTopLevel (/Users/shawnlim/Documents/Code/reactjs/boa/node_modules/jsxgettext/node_modules/acorn/acorn.js:1526:18)
    at Object.exports.parse (/Users/shawnlim/Documents/Code/reactjs/boa/node_modules/jsxgettext/node_modules/acorn/acorn.js:48:12)
    at /Users/shawnlim/Documents/Code/reactjs/boa/node_modules/jsxgettext/lib/jsxgettext.js:128:27

Nunjucks inline if statement

Hi

It seems that Nunjucks inline if statement causing error in parsing:

Whenever I try to parse that file https://github.com/LotusTM/Kotsu/blob/master/source/layouts/_layout.nj it throughs following error:

λ grunt abideExtract
Running "abideExtract:html" (abideExtract) task

C:\Users\ArmorDarks\AppData\Roaming\npm\node_modules\jsxgettext\node_modules\acorn\acorn.js:321
    throw err;
          ^
SyntaxError: Unexpected token (19:11)
    at raise (C:\Users\ArmorDarks\AppData\Roaming\npm\node_modules\jsxgettext\node_modules\acorn\acorn.js:319:15)
    at unexpected (C:\Users\ArmorDarks\AppData\Roaming\npm\node_modules\jsxgettext\node_modules\acorn\acorn.js:1311:5)
    at semicolon (C:\Users\ArmorDarks\AppData\Roaming\npm\node_modules\jsxgettext\node_modules\acorn\acorn.js:1298:47)
    at parseExpressionStatement (C:\Users\ArmorDarks\AppData\Roaming\npm\node_modules\jsxgettext\node_modules\acorn\acorn.js:1736:5)
    at parseStatement (C:\Users\ArmorDarks\AppData\Roaming\npm\node_modules\jsxgettext\node_modules\acorn\acorn.js:1525:19)
    at parseTopLevel (C:\Users\ArmorDarks\AppData\Roaming\npm\node_modules\jsxgettext\node_modules\acorn\acorn.js:1469:18)
    at Object.exports.parse (C:\Users\ArmorDarks\AppData\Roaming\npm\node_modules\jsxgettext\node_modules\acorn\acorn.js:47:12)
    at C:\Users\ArmorDarks\AppData\Roaming\npm\node_modules\jsxgettext\lib\jsxgettext.js:128:27
    at Array.forEach (native)
    at parse (C:\Users\ArmorDarks\AppData\Roaming\npm\node_modules\jsxgettext\lib\jsxgettext.js:125:24)
Fatal error: Command "C:\Users\ArmorDarks\AppData\Roaming\npm\jsxgettext source/layouts/_layout.nj -o locale\templates\LC_MESSAGES\messages.pot --join-existing --language Jinja" exited with a non-zero status

It appears only if I try to run particularly this file — no issues with other.

Seems that following line causing troubles:

<title>{{ pageTitle if pageTitle else site.name }}</title>

Nunjucks is pretty close to Jinja and if I'm not wrong, that inline statement shouldn't cause any troubles for parser, but it does.

Installing dependency estraverse fails

Estraverse has recently pushed a version 1.1.2-1 and removed 1.1.2. This leads to

npm install jsxgettext

failing miserably.

npm show estraverse

confirms, that version 1.1.2 cannot be found.

project overlap / parser separation

I've been working on xgettext-template for a while, which seems to be very similar to this project.
I haven't looked into things enough to see what's different (besides language support), so I'm avoiding the overlap-subject for now.

I came here with this question: since I was working on Swig-parsing, I wondered if you would consider splitting up the parser(s) into (a) different sub-project(s)?
xgettext-template was recently restructured with that in mind: the Handlebars parser is a separate project that can be used independently from the main project (basically the CLI interface). Definitely feel free to use it (it doesn't rely on regex's, but on the Handlebars lib itself).

Implemented gettext functions

singular

  • gettext( key )

plural

#51

  • ngettext( singular_key, plural_key, value )

domain

#94

  • dgettext( domain, key )
  • dngettext( domain, singular_key, plural_key, value )

context

#94

  • pgettext( context, key )
  • npgettext( context, singular_key, plural_key, value )

domain and context

#94

  • dpgettext( domain, context, key )
  • dnpgettext( domain, context, singular_key, plural_key, value )

category

  • dcgettext( domain, key, category )
  • dcngettext( domain, singular_key, plural_key, value, category )
  • dcnpgettext( domain, context, singular_key, plural_key, value, category )

I hope that will help to have better view of project state.

Renaming JS to JavaScript in command line options

Would you consider renaming language identifier "JS" to "JavaScript", eg. instead of running

jsxgettext --language=JS file.js

the correct way would be

jsxgettext --language=JavaScript file.js

As far as I understood, this change wouldn't mean anything else than changing the help text, since all but "EJS" is already interpreted as JavaScript by default. Any existing code using "JS" as the language identifier would continue working without change.

This would be great in terms of xgettext compatibility - in this way it would be possible to use either jsxgettext or xgettext (>=0.18.3) as the engine for processing javascript files without changing any params.

CLI syntax differs from xgettext

Original GNU xgettext uses xgettext [option] <inputfile> syntax. At the same time jsxgettext uses jsxgettext uses jsxgettext <inpfile> [options], thus the two utilities have incompatible syntax.

Comments aren't extracted for jinja

Comments like {# L10n: This is comment #} should be extracted when using the jinja format but it looks like the jinja parser only processes text between '{{' and '}}'.

Extracting comments

Although mentioned in the README, the extraction of translator comments from the source code is not working. It looks like the function findComments is never even called.

@plemarquand seems to have figured out how to do this including proper tests.
plemarquand@6c3d0be

Support for comments should also follow the standard gettext format for translator comments, i.e. comments beginning with a triple slash /// (at least in plain JavaScript files).

Is there any chance for this to get merged into the main distribution of jsxgettext?

Use standart input/output

As I see from the source code the CLI should works fine with stdin and stdout but it does not. I've made some investigations and it seems that a dash argument (-) is incorrectly treated as a flags.

Thus there is actually no way to use stdin and stdout with the CLI.

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.