in tools/i18n/update.js [150:192]
function applyTranslationsToDocument(xlfJson, stringsById) {
Object.getOwnPropertyNames(xlfJson.items).forEach(function (id) {
var item = xlfJson.items[id];
var string = stringsById[id];
if (!string) {
console.log(chalk.yellow.bold('Warning: Couldn\'t find information for loc id: ' + id));
return;
}
var parentElement = string.parentElement;
var pos = id.lastIndexOf('-');
if (pos > 0) {
var attributeName = id.substring(0, pos);
parentElement.attribs[attributeName] = item.translatedText;
} else {
var newNodes = parse5.parseFragment(item.translatedText, {treeAdapter: htmlparser2TreeAdapter}).children;
// We want to remove the child nodes stored for this string, and insert the generated nodes in
// the same spot.
var nextSibling;
string.nodes.forEach(function (node) {
if (node.parent === parentElement) {
nextSibling = node.nextSibling;
htmlparser2TreeAdapter.detachNode(node);
}
});
// Since we re-use this same document for each language, update the stored child nodes for this
// string with the ones we're about to insert.
string.nodes = newNodes;
// Insert the new nodes before the next sibling, or at the end if there is no next sibling
newNodes.forEach(function (node) {
if (nextSibling) {
htmlparser2TreeAdapter.insertBefore(parentElement, node, nextSibling);
} else {
htmlparser2TreeAdapter.appendChild(parentElement, node);
}
});
}
});
}