jsxgettext
Advanced tools
Comparing version 0.7.0 to 0.8.0
@@ -47,3 +47,4 @@ "use strict"; | ||
funcName = callee.object.name || prop && (prop.name || prop.value); | ||
arg = node.arguments[1]; // skip context object | ||
node.arguments = node.arguments.slice( 1 ); // skip context object | ||
arg = node.arguments[0]; | ||
} else { | ||
@@ -57,2 +58,6 @@ funcName = callee.property.name; | ||
// If the gettext function's name starts with "n" (i.e. ngettext or n_) and its first 2 arguments are strings, we regard it as a plural function | ||
if (arg && funcName.substr(0, 1) === "n" && (isStrConcatExpr(arg) || isStringLiteral(arg)) && node.arguments[1] && (isStrConcatExpr(node.arguments[1]) || isStringLiteral(node.arguments[1]))) | ||
return [arg, node.arguments[1]]; | ||
if (arg && (isStrConcatExpr(arg) || isStringLiteral(arg))) | ||
@@ -121,3 +126,10 @@ return arg; | ||
options.keyword = options.keyword || ['gettext']; | ||
if( options.keyword ) { | ||
Object.keys(options.keyword).forEach(function (index) { | ||
options.keyword.push('n' + options.keyword[index]); | ||
}); | ||
} | ||
else { | ||
options.keyword = ['gettext', 'ngettext']; | ||
} | ||
var tagName = options.addComments || "L10n:"; | ||
@@ -162,3 +174,6 @@ var commentRegex = new RegExp([ | ||
var str = extractStr(arg); | ||
var msgid = arg; | ||
if( arg.constructor === Array ) | ||
msgid = arg[0]; | ||
var str = extractStr(msgid); | ||
var line = node.loc.start.line; | ||
@@ -177,2 +192,6 @@ var comments = findComments(astComments, line); | ||
}; | ||
if( arg.constructor === Array ) { | ||
translations[str].msgid_plural = extractStr(arg[1]); | ||
translations[str].msgstr = ['', '']; | ||
} | ||
} else { | ||
@@ -179,0 +198,0 @@ if(translations[str].comments) { |
@@ -37,12 +37,14 @@ "use strict"; | ||
var buf = [], lineN, lineAdjust = -1; | ||
var buf = []; | ||
function append(text) { | ||
function append(text, offset) { | ||
/* jshint -W040 */ | ||
var ctx = this; | ||
if (ctx && ctx.bump) { | ||
lineN += 1; | ||
if (this.type === 'attrs') { | ||
// offset for attribute tokens are invalid | ||
// we treat all attr tokens to be on the same line as the first one =( | ||
offset = 0; | ||
} | ||
var line = this.line + (offset || 0) - 1; | ||
if (text.length) { | ||
buf[lineN] = [buf[lineN], text, ';'].join(''); | ||
buf[line] = [buf[line], text, ';'].join(''); | ||
} | ||
@@ -53,3 +55,2 @@ } | ||
token = lexer.next(); | ||
lineN = token.line + lineAdjust; | ||
switch (token.type) { | ||
@@ -59,17 +60,17 @@ case 'attrs': | ||
.map(extractFromObj, token.attrs) | ||
.forEach(append); | ||
.forEach(append, token); | ||
break; | ||
case 'text': | ||
case 'code': | ||
append(extractGettext(token.val)); | ||
append.call(token, extractGettext(token.val)); | ||
break; | ||
case 'pipeless-text': | ||
token.line -= token.val.length - 1; | ||
token.val | ||
.map(extractGettext) | ||
.forEach(append, { bump: true }); | ||
lineAdjust += token.val.length; | ||
.forEach(append, token); | ||
break; | ||
case 'comment': | ||
if (/^\s*L10n:/.test(token.val)) { | ||
append(['/*', token.val, '*/'].join('')); | ||
append.call(token, ['/*', token.val, '*/'].join('')); | ||
} | ||
@@ -76,0 +77,0 @@ break; |
@@ -19,2 +19,3 @@ { | ||
"Andris Reinman <andris.reinman@gmail.com> (http://www.andrisreinman.com)", | ||
"Valentin Rouet <v.rouet@gmail.com> (https://github.com/vrouet)", | ||
"Michael Weibel (https://github.com/mweibel)", | ||
@@ -26,3 +27,3 @@ | ||
"name": "jsxgettext", | ||
"version": "0.7.0", | ||
"version": "0.8.0", | ||
"license": "MPL-2.0", | ||
@@ -49,3 +50,3 @@ "description": "Extracts gettext strings from JavaScript, EJS, Jade, Jinja and Handlebars files.", | ||
"commander": "2.5.0", | ||
"jade": "^1.0.0", | ||
"jade": "^1.11.0", | ||
"escape-string-regexp": "1.0.1" | ||
@@ -52,0 +53,0 @@ }, |
@@ -7,5 +7,9 @@ # jsxgettext [![Build Status](https://travis-ci.org/zaach/jsxgettext.png)](https://travis-ci.org/zaach/jsxgettext) [![NPM version](https://badge.fury.io/js/jsxgettext.png)](http://badge.fury.io/js/jsxgettext) | ||
gettext("Hello world!"); | ||
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); | ||
``` | ||
@@ -12,0 +16,0 @@ |
@@ -5,3 +5,4 @@ (function () {})('Ignore me'); | ||
somemethod: function () {}, | ||
gettext: function () {} | ||
gettext: function () {}, | ||
ngettext: function () {} | ||
}; | ||
@@ -11,1 +12,2 @@ | ||
testObj.gettext("I'm gonna get translated, yay!"); | ||
testObj.ngettext("I'm also gonna get translated!", "I'm the plural form!", 2); |
@@ -6,1 +6,11 @@ gettext( | ||
); | ||
ngettext( | ||
"This is another quite long sentence "+ | ||
"and we'd like to concatenate it in our source "+ | ||
"code to avoid really wide files.", | ||
"This is the plural version of our quite long sentence "+ | ||
"that we'd like to concatenate it in our source "+ | ||
"code to avoid really wide files.", | ||
3 | ||
); |
@@ -6,3 +6,6 @@ var templates = { | ||
subject2: test.gettext.call(test, "Confirm email address for Persona 2"), | ||
subject3: test.something.someotherthing['gettext'].call(test, "Confirm email address for Persona 3", somethingelse) | ||
subject3: test.something.someotherthing['gettext'].call(test, "Confirm email address for Persona 3", somethingelse), | ||
subject4: test.ngettext("Confirm email address for Persona 4", "Confirm email address for Persona 4 plural", 4), | ||
subject5: test.ngettext.call(test, "Confirm email address for Persona 5", "Confirm email address for Persona 5 plural", 5), | ||
subject6: test.something.someotherthing['ngettext'].call(test, "Confirm email address for Persona 6", "Confirm email address for Persona 6 plural", 6, somethingelse) | ||
} | ||
@@ -9,0 +12,0 @@ }; |
var msg = gettext('Hello World'); | ||
var dup = gettext('This message is used twice.'); | ||
var dup = gettext('This message is used twice.'); | ||
var dup2 = ngettext('This other message is used twice.', 'This other message is used twice. - plural', 2); |
_('should be translatable'); | ||
t('should also be translatable'); | ||
gettext('should NOT be translatable since we did not define it as keyword'); | ||
n_('should be translatable - singular', 'should be translatable - plural', 2); | ||
nt('should also be translatable - singular', 'should also be translatable - plural', 2); | ||
ngettext('should NOT be translatable since we did not define it as keyword - singular', 'should NOT be translatable since we did not define it as keyword - plural', 2); |
@@ -1,1 +0,2 @@ | ||
var dup = gettext('This message is used twice.'); | ||
var dup = gettext('This message is used twice.'); | ||
var dup2 = ngettext('This other message is used twice.', 'This other message is used twice. - plural', 2); |
@@ -21,2 +21,4 @@ "use strict"; | ||
'localizable strings are extracted'); | ||
assert.ok(result.indexOf('this is a localizable plural string') !== -1, | ||
'localizable plural strings are extracted'); | ||
cb(); | ||
@@ -23,0 +25,0 @@ }); |
@@ -21,2 +21,4 @@ "use strict"; | ||
'raw localizable strings are extracted'); | ||
assert.ok(result.indexOf('this is a raw localizable plural string') !== -1, | ||
'raw localizable plural strings are extracted'); | ||
cb(); | ||
@@ -23,0 +25,0 @@ }); |
@@ -21,2 +21,4 @@ "use strict"; | ||
'localizable strings are extracted'); | ||
assert.ok(result.indexOf('this is a localizable plural string') !== -1, | ||
'localizable plural strings are extracted'); | ||
cb(); | ||
@@ -23,0 +25,0 @@ }); |
@@ -7,8 +7,10 @@ "use strict"; | ||
// Ignore the header | ||
result = result.slice(result.indexOf('\n\n') + 2); | ||
result = result.slice(result.indexOf('\n\n') + 2).trimRight(); | ||
fs.readFile(filePath, function (err, source) { | ||
assert.equal(result, source.toString('utf8'), msg || 'Results match.'); | ||
var sourceContent = source.toString('utf8').trimRight(); | ||
assert.equal(result, sourceContent, msg || 'Results match.'); | ||
cb(); | ||
}); | ||
}; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
77971
1188
54
Updatedjade@^1.11.0