From 72e1723aed5f92bc28b9e4bc837be9144a12ff63 Mon Sep 17 00:00:00 2001 From: Matthieu Sieben Date: Wed, 13 Dec 2017 13:30:18 +0100 Subject: [PATCH 1/4] Fixes rubenv/angular-gettext-tools#177 Allow using `markerNames` to detect string literals. Simply add a leading comment to the string that contains the `markerName` (exactly) and that string will be added to the `pot` file. Example: ```js const myString = /* gettext */ "This will be marked" // or var extractor = new Extractor({ markerNames: [ "@ngTranslate" ] }) // This will export the following string: const myString = /* @ngTranslate */ "This will be marked" ``` --- lib/extract.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/extract.js b/lib/extract.js index 612377e..9daf728 100644 --- a/lib/extract.js +++ b/lib/extract.js @@ -212,6 +212,17 @@ var Extractor = (function () { return; } + function isAnnontatedString (node) { + return node !== null && + isStringLiteral(node) && + node.leadingComments !== null && + self.options.markerNames.some(function (markerName) { + return node.leadingComments.some(function (comment) { + return comment.value.indexOf(markerName) !== -1; + }); + }); + } + function isGettext(node) { return node !== null && node.type === 'CallExpression' && @@ -298,6 +309,8 @@ var Extractor = (function () { } else if (isTemplateElement(node)) { var line = reference.location && reference.location.start.line ? reference.location.start.line - 1 : 0; self.extractHtml(reference.file, node.value.raw, line); + } else if (isAnnontatedString(node)) { + str = getJSExpression(node); } if (str || singular) { var leadingComments = node.leadingComments || (parentComment ? parentComment.leadingComments : []); From c5f100fe423994d830de46da1bbdbffc8a7853af Mon Sep 17 00:00:00 2001 From: Matthieu Sieben Date: Wed, 13 Dec 2017 13:33:03 +0100 Subject: [PATCH 2/4] Linting --- lib/extract.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/extract.js b/lib/extract.js index 9daf728..0675ce3 100644 --- a/lib/extract.js +++ b/lib/extract.js @@ -212,12 +212,12 @@ var Extractor = (function () { return; } - function isAnnontatedString (node) { + function isAnnontatedString(node) { return node !== null && isStringLiteral(node) && node.leadingComments !== null && - self.options.markerNames.some(function (markerName) { - return node.leadingComments.some(function (comment) { + self.options.markerNames.some(function(markerName) { + return node.leadingComments.some(function(comment) { return comment.value.indexOf(markerName) !== -1; }); }); From ca3a4fd55c9489dce4f1ef7fb25c334a76a69d4d Mon Sep 17 00:00:00 2001 From: Matthieu Sieben Date: Wed, 13 Dec 2017 13:34:28 +0100 Subject: [PATCH 3/4] Linting --- lib/extract.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/extract.js b/lib/extract.js index 0675ce3..101f2a9 100644 --- a/lib/extract.js +++ b/lib/extract.js @@ -216,8 +216,8 @@ var Extractor = (function () { return node !== null && isStringLiteral(node) && node.leadingComments !== null && - self.options.markerNames.some(function(markerName) { - return node.leadingComments.some(function(comment) { + self.options.markerNames.some(function (markerName) { + return node.leadingComments.some(function (comment) { return comment.value.indexOf(markerName) !== -1; }); }); From f03327abc59e170c78d7868ff5567e33bc953faa Mon Sep 17 00:00:00 2001 From: Matthieu Sieben Date: Wed, 13 Dec 2017 13:40:07 +0100 Subject: [PATCH 4/4] node.leadingComments are `undefined`, not `null` --- lib/extract.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/extract.js b/lib/extract.js index 101f2a9..64ce9bc 100644 --- a/lib/extract.js +++ b/lib/extract.js @@ -215,7 +215,7 @@ var Extractor = (function () { function isAnnontatedString(node) { return node !== null && isStringLiteral(node) && - node.leadingComments !== null && + node.leadingComments && self.options.markerNames.some(function (markerName) { return node.leadingComments.some(function (comment) { return comment.value.indexOf(markerName) !== -1;