'; $larray = array("Translations courtesy of Google Translate at","Language","Afrikaans","Albanian","Arabic","Armenian","Azerbaijani","Basque","elarusian","Bulgarian","Catalan","Chinese (Simplified)","Chinese (Traditional)","Croatian","Czech","Danish","Dutch","English","Estonian","Filipino","Finnish","French","Galician","Georgian","German","Greek","Haitian Creole","Hebrew","Hindi","Hungarian","Icelandic","Indonesian","Irish","Italian","Japanese","Korean","Latin","Latvian","Lithuanian","Macedonian","Malay","Maltese","Norwegian","Persian","Polish","Portuguese","Romanian","Russian","Serbian","Slovak","Slovenian","Spanish","Swahili","Swedish","Thai","Turkish","Ukrainian","Urdu","Vietnamese","Welsh","Yiddish"); $lis = ""; $hl = "en"; $p = ""; $array = array("My hovercraft is full of eels.", "One language is never enough.", "Stop the world, I want to get off!", "This gentleman will pay for everything.", "This lady will pay for everything.", "Say cheese!", "Pleased to meet you.", "What's your name?", "Where are you from?", "I don't understand.", "Please say that again.", "Please speak more slowly.", "Please write it down.", "Do you speak English?", "I don't know."); $earray = array("My hovercraft is full of eels.", "One language is never enough.", "Stop the world, I want to get off!", "This gentleman will pay for everything.", "This lady will pay for everything.", "Say cheese!", "Pleased to meet you.", "What's your name?", "Where are you from?", "I don't understand.", "Please say that again.", "Please speak more slowly.", "Please write it down.", "Do you speak English?", "I don't know."); function translate($ins) { global $lis, $hl; $outs = $ins; if ($lis != "" && $lis != "en") { $huh = file_get_contents("http://www.google.com/translate_t?ie=UTF8&hl=" . $hl . "&langpair=" . $hl . "|" . $lis . "&text=" . str_replace(" ", "+", $ins)); $outs = rettrans($huh, $ins); } return $outs; } function rettrans($inhuh, $defhuh) { global $lis; $xxxx = $defhuh; $xpos = strpos($inhuh, "onmouseout"); if ($xpos !== false) { $zpos = substr($inhuh, strpos($inhuh, "onmouseout")); //if ($i == 0) echo " found at " . $xpos; $xxpos = strpos($zpos, ">"); $zzpos = substr($zpos, strpos($zpos, ">") + 1); //if ($i == 0) echo " then found at " . $xxpos; $xxxpos = strpos($zzpos, "<"); //if ($i == 0) echo " then again found at " . $xxxpos; $zzzpos = substr($zzpos, 0, strpos($zzpos, "<") - 0); $xxxx = $zzzpos; } //$fl=fopen(dirname(__FILE__) . "/myselectf." . $lis, "a"); //fwrite($fl, $xxxx . "\n"); //fclose($fl); return $xxxx; } // Fixes the encoding to uf8 // Thanks to ... http://php.net/manual/en/function.utf8-encode.php ... no mb_* on website ... boo hoo function fixEncoding($in_str) { //$cur_encoding = mb_detect_encoding($in_str) ; //if($cur_encoding == "UTF-8" && mb_check_encoding($in_str,"UTF-8")) // return $in_str; //else return utf8_encode($in_str); } // fixEncoding echo ''; echo "\n" . ''; echo "\n"; echo "\n" . ''; echo "\n" . ''; if (isset($_GET['lang'])) { $lis = $_GET['lang']; echo "\n" . translate("The Wonders of Google Translate - Small Amounts of Translation - RJM Programming tutorial"); for ($i=0; $i<sizeof($array); $i++) { if (!file_exists(dirname(__FILE__) . "/myp" . $i . "." . $lis)) { $p = $array[$i]; $huh = file_get_contents("http://www.google.com/translate_t?ie=UTF8&hl=" . $hl . "&langpair=" . $hl . "|" . $lis . "&text=" . str_replace(" ", "+", $p)); $fh = fopen(dirname(__FILE__) . "/myp" . $i . "." . $lis, "w"); fwrite($fh, $huh); fclose($fh); } else { $huh = ""; $fl=fopen(dirname(__FILE__) . "/myp" . $i . "." . $lis, "r"); while (($buffer = fgets($fl, 500000)) !== false) { $huh .= $buffer; } fclose($fl); } //if ($i == 0) echo str_replace("<", " ", str_replace(">", " ", substr($huh, strpos($huh, "onmouseout")))); $xpos = strpos($huh, "onmouseout"); if ($xpos !== false) { $zpos = substr($huh, strpos($huh, "onmouseout")); //if ($i == 0) echo " found at " . $xpos; $xxpos = strpos($zpos, ">"); $zzpos = substr($zpos, strpos($zpos, ">") + 1); //if ($i == 0) echo " then found at " . $xxpos; $xxxpos = strpos($zzpos, "<"); //if ($i == 0) echo " then again found at " . $xxxpos; $zzzpos = substr($zzpos, 0, strpos($zzpos, "<") - 0); $xxxx = $zzzpos; //if ($i == 0) echo " gives " . $xxxx; $array[$i] = rettrans($huh, $array[$i]); //$xxxx; if ($i == 0) { if (file_exists(dirname(__FILE__) . "/myselect." . $lis)) { $ls = ""; $fl=fopen(dirname(__FILE__) . "/myselect." . $lis, "r"); while (($buffer = fgets($fl, 500000)) !== false) { $ls .= $buffer; } fclose($fl); } else { $xls = $ls; $huh = file_get_contents("http://www.google.com/translate_t?ie=UTF8&hl=" . $hl . "&langpair=" . $hl . "|" . $lis . "&text=" . str_replace(" ", "+", $larray[0])); $ls = str_replace($larray[0], rettrans($huh, $larray[0]), $xls); $xls = $ls; for ($k=1; $k<sizeof($larray); $k++) { $huh = file_get_contents("http://www.google.com/translate_t?ie=UTF8&hl=" . $hl . "&langpair=" . $hl . "|" . $lis . "&text=" . str_replace(" ", "+", $larray[$k])); //$fl=fopen(dirname(__FILE__) . "/myselectf." . $lis, "a"); //fwrite($fl, "larray[" . $k . "]=" . $larray[$k] . "\n"); //fclose($fl); $ls = str_replace($larray[$k], rettrans($huh, $larray[$k]), $xls); $xls = $ls; } $fl=fopen(dirname(__FILE__) . "/myselect." . $lis, "w"); fwrite($fl, $ls); fclose($fl); } } } else if ($i == 0) { echo " not found "; } } } else { echo "\n<title>" . "The Wonders of Google Translate - Small Amounts of Translation - RJM Programming tutorial"; } echo "\n"; echo "\n"; if (isset($_GET['language'])) { $lis = $_GET['language']; echo "

... " . translate("translating from English now") . " ... " . translate("please wait") . " ...

"; } else { echo "\n"; echo "\n"; echo "\n"; if ($lis != "en" && $lis != "") { echo str_replace('value="' . $lis . '"', 'value="' . $lis . '" selected="selected"', fixEncoding($ls)); } else { echo $ls; } //echo " 
"; echo " 
"; for ($j=1; $j<=sizeof($array); $j++) { echo "\n

" . fixEncoding($array[$j - 1]) . "

"; } echo "\n
"; echo "\n"; } ?>