Fake Germanizer

I ran into a problem where I needed to guess how something would look in German, without knowing a single drop of German. So, I pulled up Mozilla’s XPath documents and made a small bookmarklet. It’s far from perfect, but it definitely has its uses when you’re trying to estimate how items will look before they reach a translation team… even if the first use was messing with my Twitter feed.

Fauxgermanhausen das Pagen! (bookmarklet)
(function () {
  var prefixes = ["", “glocken”, “das”, “borfa”, “maushe”, “uber”],
    suffixes = [
      "",
      “hausen”,
      ” die vander”,
      “gleuten”,
      “noshan”,
      “flagellan”,
      “mek”,
      “dak”,
      “en das”,
      “ga”,
    ],
    xPathResult = document.evaluate(
      “.//text()[normalize-space(.)!=”]”,
      document.body,
      null,
      XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
      null
    ),
    i,
    textNode,
    cnt,
    out,
    j,
    pfx,
    sfx;
  for (i = 0, l = xPathResult.snapshotLength; i < l; i++) {
    textNode = xPathResult.snapshotItem(i);
    if (
      textNode.parentNode.nodeName.toLowerCase() == “script” ||
      textNode.tagName == “style”
    )
      continue;
    cnt = textNode.data.split(/\s/g);
    out = [];
    for (j = 0; j < cnt.length; j++) {
      if (cnt[j].replace(/[\s]/g, "") == "") continue;
      pfx = !Math.floor(Math.random() * 10)
        ? ""
        : prefixes[Math.floor(Math.random() * prefixes.length)];
      sfx = !Math.floor(Math.random() * 10)
        ? ""
        : suffixes[Math.floor(Math.random() * suffixes.length)];
      out.push(pfx + cnt[j] + sfx);
    }
    textNode.data = ” ” + out.join(” ”) + ” ”;
  }
})();
Webmentions
What’s this?

Tweets, mentions, and trackbacksShare your thoughts

As this gets discussed, comments will show up here. If the post is new, it may take a bit for your thoughts to get from one side of the internet to the other.

Code Drift is the personal website of Rudolph Jakob Heuser