Dirty Hungarian Dictionaries

Language::Farnsworth::Functions::GoogleTranslate has been spun off into its own dist on cpan, i've done that simply because it won't be updated except to add new languages for the time being. (unless i break it, or make a proper plugin system). So if you're wanting to use those nice fancy translation features, you'll want to install it also, and for those of you who are wondering i'll also provide here a copy of the string mangling function that the bot uses.
var steps = [];
var languages = ["Arabic","Bulgarian","Catalan","Czech","Danish","German",

var getlang = {`` languages@random[]*(length[languages])$};

mangle{x} := {steps = [];
              var origlang = x -> DetectLanguage;
              push[steps, x];
              var targetlangs = int[random[]*42]+1;

              while (targetlangs=targetlangs-1)
                push[steps, eval["steps@-1$ -> "+getlang[]]];

              push[steps, eval["steps@-1$ -> "+origlang]];

tracemangle{} := {steps};

} []; /*this bit makes the lambda we just finished making get executed rather than storing it somewhere*/
What's going on in it is that we've got two main variables that we don't really want to expose to the world, for pollution and protection reasons (a bit like using an object!). So what we do is we make a lambda since it has its own scope and define everything inside of it, event the functions that are exposed to the outside world by virtue of going into the function namespace. Even though they're accessible to the world they still live inside the scope of the original lambda allowing them to use the two variables steps, languages and getlang. languages should be fairly self explanatory, its a list of all the languages that the google translate library supports. getlang is a little harder but still somewhat easy to figure out, its a lambda that gets a random language from the languages variable. steps is a little strange, we store each and every result that we get from google translate so that we can later examine them with the tracemangle[] function (i.e. to figure out where it got "purple monkey dishwasher" from). The two functions it exports out to the world, tracemangle[] and mangle[] are pretty simple to understand. tracemangle[] is just a simple getter for the internal steps variable. mangle[] starts by clearing the last steps we took, and then by using the DetectLanguage[] function provided by the translation library to find out what language we're starting with, this will be used later on. After that we pick a random number of languages to translate to (we use the 42 simply because it seems to work well when played with, other values work fine but well 42...). Then we go into a fairly simple while loop (the language still does not have any for loops, which will be recitfied) that uses the eval[] function to create and run a simple snippet of code that looks something like:
steps@-1$ -> Japanese
The reason we use the variable steps is that it helps prevent someone from inserting their own code to be run. We do this until we've done the requisite number of translations that we decided on before, and then we do ONE more translation. This time we go and do a translation into the original source language found from DetectLanguage[]. This allows us to mangle things from any language into any language and makes a few of the Dutch people that use the bot happy.

Published: April 30 2010

  • category:
  • tags:
blog comments powered by Disqus