fabi1cazenave / webL10n

Client-side internationalization / localization library
http://fabi1cazenave.github.com/webL10n/
279 stars 71 forks source link

Use webL10n on documentFragment #73

Closed Phyks closed 9 years ago

Phyks commented 9 years ago

Hi,

The function

  function translateFragment(element) {
    element = element || document.documentElement;

    // check all translatable children (= w/ a `data-l10n-id' attribute)
    var children = getTranslatableChildren(element);
    var elementCount = children.length;
    for (var i = 0; i < elementCount; i++) {
      translateElement(children[i]);
    }

    // translate element itself if necessary
    translateElement(element);
  }

in webL10n should be able to translate a documentFragment, I think, and is exposed as translate in the public API.

But the last call to translateElement(element) fails in such a case as it is not possible to getAttributes of a documentFragment. What about encapsulating it in a test to not call it on documentFragment elements?

Rob--W commented 9 years ago

Patches are welcome. Best fix is probably checking for nodeType === 1 in translateElement (Node.ELEMENT_NODE) and returning otherwise.

Phyks commented 9 years ago

Closed by PR #74.