angular-gettext icon indicating copy to clipboard operation
angular-gettext copied to clipboard

Custom attributes translation extracts inner html instead of attribute value

Open aszczepanek opened this issue 7 years ago • 1 comments

Configuration: { attributes: ["title"] }

Example html: <div title="Some hint for user"> <div>Header</div> <div>Some content to read</div> < /div>

Current implementation will extract inner html (<div>Header...) instead of title attribute value, probably because of this lines: 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); }

It works only for attributes on elements without closing tag like input: <input type="text" placeholder="This text can be extracted" title="This text can also be extracted">

There is no tag so node.html() returns nothing so getAttr can execute.

aszczepanek avatar May 11 '18 13:05 aszczepanek

@aszczepanek did you fixed this problem without angular-gettext modifications?

I found that substituting this:

self.addString(reference(n.startIndex), str || getAttr(attr) || '', attrValue.plural, attrValue.extractedComment, attrValue.context);

With this:

self.addString(reference(n.startIndex), getAttr(attr) || str || '', attrValue.plural, attrValue.extractedComment, attrValue.context);

Solves the problem

dakk avatar Jun 14 '18 16:06 dakk