From 5a3e3ef6e1ec5279dd1dbb30ca77e04cdb16950f Mon Sep 17 00:00:00 2001 From: Bart Butler Date: Sun, 10 Apr 2016 17:39:36 -0700 Subject: [PATCH 1/3] Fix value order for custom translation attribute extraction When using a custom directive on an attribute, the extracted string should default to the value of the attribute, and if not present, fallback to the HTML inside the tag. --- lib/extract.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/extract.js b/lib/extract.js index 23c5bc3..34395c8 100644 --- a/lib/extract.js +++ b/lib/extract.js @@ -352,7 +352,7 @@ var Extractor = (function () { if (possibleAttributes.indexOf(attr) > -1) { var attrValue = extracted[attr]; str = node.html(); // this shouldn't be necessary, but it is - self.addString(reference(n.startIndex), str || getAttr(attr) || '', attrValue.plural, attrValue.extractedComment, attrValue.context); + self.addString(reference(n.startIndex), getAttr(attr) || str || '', attrValue.plural, attrValue.extractedComment, attrValue.context); } else if (matches = self.noDelimRegex.exec(node.attr(attr))) { str = matches[2].replace(/\\\'/g, '\''); self.addString(reference(n.startIndex), str); From 5c95332d852380f276e54d18fe682a771f68a072 Mon Sep 17 00:00:00 2001 From: Bart Butler Date: Sun, 10 Apr 2016 19:53:36 -0700 Subject: [PATCH 2/3] Treat attribute "translate" as special case --- lib/extract.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/extract.js b/lib/extract.js index 34395c8..d558f1c 100644 --- a/lib/extract.js +++ b/lib/extract.js @@ -351,8 +351,14 @@ var Extractor = (function () { if (possibleAttributes.indexOf(attr) > -1) { var attrValue = extracted[attr]; - str = node.html(); // this shouldn't be necessary, but it is - self.addString(reference(n.startIndex), getAttr(attr) || str || '', attrValue.plural, attrValue.extractedComment, attrValue.context); + if ( attr === 'translate' ) { + // Compatibility with translate="translate" attribute syntax + str = node.html() || getAttr(attr) || ''; + } + else { + str = getAttr(attr) || node.html() || ''; + } + self.addString(reference(n.startIndex), str, attrValue.plural, attrValue.extractedComment, attrValue.context); } else if (matches = self.noDelimRegex.exec(node.attr(attr))) { str = matches[2].replace(/\\\'/g, '\''); self.addString(reference(n.startIndex), str); From 6dcb6f62bbf21df1c65e6ac667a09f074b02d6f1 Mon Sep 17 00:00:00 2001 From: Bart Butler Date: Sun, 10 Apr 2016 19:59:52 -0700 Subject: [PATCH 3/3] Code standards --- lib/extract.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/extract.js b/lib/extract.js index d558f1c..929c627 100644 --- a/lib/extract.js +++ b/lib/extract.js @@ -354,8 +354,7 @@ var Extractor = (function () { if ( attr === 'translate' ) { // Compatibility with translate="translate" attribute syntax str = node.html() || getAttr(attr) || ''; - } - else { + } else { str = getAttr(attr) || node.html() || ''; } self.addString(reference(n.startIndex), str, attrValue.plural, attrValue.extractedComment, attrValue.context);