angular-gettext
angular-gettext copied to clipboard
Custom attributes translation extracts inner html instead of attribute value
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 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