Skip to content

Commit

Permalink
Use esprima for speed. Only add comments that begin with L10n.
Browse files Browse the repository at this point in the history
  • Loading branch information
zaach committed Jul 2, 2012
1 parent 7cec2a5 commit 895f6b8
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
11 changes: 6 additions & 5 deletions jsxgettext.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
const fs = require('fs');
const path = require('path');

const reflect = require('reflect').Reflect;
const parser = require('esprima');
const escodegen = require('escodegen');

const generate = escodegen.generate;
Expand All @@ -11,7 +11,7 @@ const traverse = escodegen.traverse;

// generate extracted strings file
function gen (source, filename) {
var ast = reflect.parse(source, {comment: true, tokens: true, loc: true});
var ast = parser.parse(source, {comment: true, tokens: true, loc: true});
var generated = '';

traverse(ast, {
Expand All @@ -23,7 +23,7 @@ function gen (source, filename) {
) {
return;
}
var str = node.arguments[0].raw;
var str = JSON.stringify(node.arguments[0].value);
var line = node.loc.start.line;
var comments = findComments(ast.comments, line);

Expand All @@ -41,8 +41,9 @@ function gen (source, filename) {
var found = '';
comments.forEach(function (node) {
var commentLine = lineFromRange(node.range);
if ((node.type == 'Line' && commentLine == line) ||
(node.type == 'Block' && commentLine + 1 == line)) {
if (node.value.match(/^\s*L10n/) &&
(commentLine == line ||
commentLine + 1 == line)) {
found += node.value;
}
});
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"main": "jsxgettext.js",
"dependencies": {
"escodegen": ">=0.0.4",
"reflect": ">=0.1.2"
"esprima": ">=0.9.9"
},
"devDependencies": {
"test": "*"
Expand Down
7 changes: 4 additions & 3 deletions wait-messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,22 @@ BrowserID.Wait = (function(){

var Wait = {
authentication: {
/* test block */
/* L10n: test block */
title: gettext("Finishing Sign In..."),
message: gettext("In just a moment you'll be signed into BrowserID.")
},

generateKey: {
title: gettext("Finishing Sign In..."),
/* test multi
/* L10n: test multi
* line */
message: gettext("Please wait a few seconds while we sign you into the site.")
},

slowXHR: {
// test single comment
// L10n: test single line comment
title: gettext("We are sorry, this request is taking a LOOONG time."),
// ignore this comment
message: gettext("This message will go away when the request completes (hopefully soon). If you wait too long, close this window and try again."),
id: "slowXHR"
}
Expand Down

0 comments on commit 895f6b8

Please sign in to comment.