Location: PHPKode > scripts > GTranslator > gtranslator/index.php
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Google Translator Service</title>
</head>
<body>
<?php
    require ("google.translator.class.php");
    function bool_to_str($val){
        if ($val) return "yes"; else return "no";
    }
    //The key, I never chek this if this api need any key at all, leave it be.
    $translator=new GTranslator();    
    if (isset($_POST['translateme'])){
		echo "<h1>detect language result</h1>";
        //You can check any thing here, for me, in this example its enaugh to chek the results...
        $detect= $translator->detect_language($_POST['translateme']);
        $responseData=$detect['responseData'];
        if (is_array($responseData)){
            echo "Detected language is : " . $responseData['language'] . ' - ' . 
                $translator->get_name_of($responseData['language']) .'<br />';
            echo "Is reliable : " . bool_to_str( $responseData['isReliable']). "<br />";
            echo "confidence : " . $responseData['confidence']. "<br />"; 
        }else {
            echo "Error : ". $responseData['responseDetails'] . "<br />"  ;  
        }
        echo "<h1>Translate result</h1>";
        $trans=$translator->translate($_POST['translateme'],$_POST['from_lang'],$_POST['to_lang']);
        $responseData=$trans['responseData'];
        if (is_array($responseData)){  
            if (isset($responseData['detectedSourceLanguage']))
                echo "Detected language is : " . $responseData['detectedSourceLanguage'] . ' - ' . 
                    $translator->get_name_of($responseData['detectedSourceLanguage']) .'<br />';   
            echo "Translated text :<br />";
            echo $responseData['translatedText'];
        }else {
            echo "Error : ". $responseData['responseDetails'] . "<br />"  ; 
        }
        
        
    }  
    
    $valids=$translator->get_valid_language();
    $select="";
    foreach ($valids as $lang_id=>$lang_name){
        if ($lang_id!="auto")
            $select.="<option value='$lang_id'>$lang_name</option>\n";
    }
?>

<form action="<?=$_SERVER['PHP_SELF']?>" method="post" >
    <label for="translateme" style="display:block">Translate this : </label><textarea  style="width:300px;height:100px" name="translateme"></textarea>
    <label for="from_lang" style="display:block">From:<label><select name="from_lang"><option value="auto">Detect language</option><?=$select?></select>
    <label for="to_lang" style="display:block">To:<label><select name="to_lang"><?=$select?></select>
    <br /><input type="submit" value="Translate" name="translate" />
</form>
</body>
</html>
Return current item: GTranslator