function translateElement(element, translation) {
  const { value } = translation;

  if (typeof value === "string") {
    if (
      element.localName === "title" &&
      element.namespaceURI === "http://www.w3.org/1999/xhtml"
    ) {
      // A special case for the HTML title element whose content must be text.
      element.textContent = value;
    } else if (!reOverlay.test(value)) {
      // If the translation doesn't contain any markup skip the overlay logic.
      element.textContent = value;
    } else {
      // Else parse the translation's HTML using an inert template element,
      // sanitize it and replace the element's content.
      const templateElement = element.ownerDocument.createElementNS(
        "http://www.w3.org/1999/xhtml",
        "template"
      );
      templateElement.innerHTML = value;
      overlayChildNodes(templateElement.content, element);
    }
  }

  // Even if the translation doesn't define any localizable attributes, run
  // overlayAttributes to remove any localizable attributes set by previous
  // translations.
  overlayAttributes(translation, element);
}
Translate an element.

Translate the element's text content and attributes. Some HTML markup is
allowed in the translation. The element's children with the data-l10n-name
attribute will be treated as arguments to the translation. If the
translation defines the same children, their attributes and text contents
will be used for translating the matching source child.

@param   {Element} element
@param   {Object} translation
@private