I was asking myself how to identify the default language Abacus should use, and I realized there's really no DOM-defined procedure for getting the language of an element.
This is rather important to me.
I've started writing out a little JS to figure out how to get an element's default language, which is inherited per the HTML 4.01 specification (and probably in XML 1.0 as well, for xml:lang)
function getLanguage(aElement) {
var walker = aElement.ownerDocument.createTreeWalker(aElement.ownerDocument, NodeFilter.SHOW_ELEMENT, hasLangAttrFilter, true);
var rv = null;
var aNode = null;
walker.currentNode = aElement;
if (hasLangAttrFilter.acceptNode(aElement) == NodeFilter.FILTER_ACCEPT) {
aNode = aElement;
} else {
aNode = walker.parentNode();
}
}
rv = aNode.getAttributeNS(XML_NS, "lang") || aNode.getAttribute("lang");
return rv;
}
hasLangAttrFilter = {
acceptNode: function(aNode) {
if (aNode.hasAttributeNS(XML_NS, "lang") || aNode.hasAttribute("lang")) {
return NodeFilter.FILTER_ACCEPT;
}
return NodeFilter.FILTER_SKIP;
}
}