pdfjs/web/l10n.js
function translateElement(element) {
    var l10n = getL10nAttributes(element);
    if (!l10n.id)
      return;

    // get the related l10n object
    var data = getL10nData(l10n.id, l10n.args);
    if (!data) {
      console.warn('#' + l10n.id + ' is undefined.');
      return;
    }

    // translate element (TODO: security checks?)
    if (data[gTextProp]) { // XXX
      if (getChildElementCount(element) === 0) {
        element[gTextProp] = data[gTextProp];
      } else {
        // this element has element children: replace the content of the first
        // (non-empty) child textNode and clear other child textNodes
        var children = element.childNodes;
        var found = false;
        for (var i = 0, l = children.length; i < l; i++) {
          if (children[i].nodeType === 3 && /\S/.test(children[i].nodeValue)) {
            if (found) {
              children[i].nodeValue = '';
            } else {
              children[i].nodeValue = data[gTextProp];
              found = true;
            }
          }
        }
        // if no (non-empty) textNode is found, insert a textNode before the
        // first element child.
        if (!found) {
          var textNode = document.createTextNode(data[gTextProp]);
          element.insertBefore(textNode, element.firstChild);
        }
      }
      delete data[gTextProp];
    }

    for (var k in data) {
      element[k] = data[k];
    }
  }
function translateElement(element) {
    var l10n = getL10nAttributes(element);
    if (!l10n.id)
      return;

    // get the related l10n object
    var data = getL10nData(l10n.id, l10n.args);
    if (!data) {
      console.warn('#' + l10n.id + ' is undefined.');
      return;
    }

    // translate element (TODO: security checks?)
    if (data[gTextProp]) { // XXX
      if (getChildElementCount(element) === 0) {
        element[gTextProp] = data[gTextProp];
      } else {
        // this element has element children: replace the content of the first
        // (non-empty) child textNode and clear other child textNodes
        var children = element.childNodes;
        var found = false;
        for (var i = 0, l = children.length; i < l; i++) {
          if (children[i].nodeType === 3 && /\S/.test(children[i].nodeValue)) {
            if (found) {
              children[i].nodeValue = '';
            } else {
              children[i].nodeValue = data[gTextProp];
              found = true;
            }
          }
        }
        // if no (non-empty) textNode is found, insert a textNode before the
        // first element child.
        if (!found) {
          var textNode = document.createTextNode(data[gTextProp]);
          element.insertBefore(textNode, element.firstChild);
        }
      }
      delete data[gTextProp];
    }

    for (var k in data) {
      element[k] = data[k];
    }
  }
function translateElement ( element ) { var l10n = getL10nAttributes ( element ) ; if ( ! l10n . id ) return ; // get the related l10n object var data = getL10nData ( l10n . id , l10n . args ) ; if ( ! data ) { console . warn ( '#' + l10n . id + ' is undefined.' ) ; return ; } // translate element (TODO: security checks?) if ( data [ gTextProp ] ) { // XXX if ( getChildElementCount ( element ) === 0 ) { element [ gTextProp ] = data [ gTextProp ] ; } else { // this element has element children: replace the content of the first // (non-empty) child textNode and clear other child textNodes var children = element . childNodes ; var found = false ; for ( var i = 0 , l = children . length ; i < l ; i ++ ) { if ( children [ i ] . nodeType === 3 && / \S / . test ( children [ i ] . nodeValue ) ) { if ( found ) { children [ i ] . nodeValue = '' ; } else { children [ i ] . nodeValue = data [ gTextProp ] ; found = true ; } } } // if no (non-empty) textNode is found, insert a textNode before the // first element child. if ( ! found ) { var textNode = document . createTextNode ( data [ gTextProp ] ) ; element . insertBefore ( textNode , element . firstChild ) ; } } delete data [ gTextProp ] ; } for ( var k in data ) { element [ k ] = data [ k ] ; } }
translate an HTML element
translate an HTML element