User:Mutante/translate


 * 1) translate English words to other languages by asking en.wiktionary
 * 2) input: 1.) an English word 2.) any other language name
 * 3) output: translation of the English word to that other language
 * 4) additionally checks if the page for 1.) exists and adds   for another bot to display the page URL
 * 5) additionally checks if 2.) is either not linked, red link (not existing) or blue link (existing)
 * 6) by Mutante 2009
 * 7) in use on #wiktionary on Freenode, as a part of the bot know-it-all.

function translate ($word,$language) {

ini_set('user_agent', 'a friendly IRC bot');

$baseurl="http://en.wiktionary.org/wiki/".$word; $buffer=file_get_contents($baseurl);

if (stripos($buffer,"$language")){ # echo "NO LINK"; $boombang=explode("$language",$buffer); $boombang=explode("title=\"",$boombang[1]);  $boombang=explode("\"",$boombang[1]); $translation=$boombang[0]; $linkstatus="no"; } elseif (stripos($buffer,"<a href=\"/wiki/$language\"",$buffer); $boombang=explode("title=\"",$boombang[1]);  $boombang=explode("\"",$boombang[2]); $translation=$boombang[0]; $linkstatus="blue"; }

if (!stripos($translation,"(page does not exist)")) { $translation="$translation"; }

$return_string="'$word' in $language is '$translation' ($linkstatus language link)";

return $return_string;

}