<?php

// Yahoo Yql Google for Two Translate Tutorial - RJM Programming - 2014

$ta11 = "";
$language1 = "en";
$x = "";
$y = "";
if (isset($_POST['ta11'])) $ta11 = str_replace(" ","%20",$_POST['ta11']);
if (isset($_GET['ta11'])) $ta11 = str_replace(" ","%20",$_GET['ta11']);
if (isset($_POST['language1'])) $x = "language2";
if (isset($_GET['language1'])) $x = "language2";
if (isset($_POST['language1'])) $language1 = str_replace(" ","%20",$_POST['language1']);
if (isset($_GET['language1'])) $language1 = str_replace(" ","%20",$_GET['language1']);
if (isset($_POST['ta22'])) $ta11 = str_replace(" ","%20",$_POST['ta22']);
if (isset($_GET['ta22'])) $ta11 = str_replace(" ","%20",$_GET['ta22']);
if (isset($_POST['language2'])) $language1 = str_replace(" ","%20",$_POST['language2']);
if (isset($_GET['language2'])) $language1 = str_replace(" ","%20",$_GET['language2']);
$bcolours = array("white", "pink", "aqua", "lime", "silver", "lightyellow", "cyan", "fuchsia", "orange", "lightblue", "lightgreen", "lightgray");

if ($ta11 != "") {
 $pageContent = file_get_contents("https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20google.translate%20where%20q%3D%22" . $ta11 . "%22%20and%20target%3D%22" . $language1 . "%22%3B&format=json&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=");

 $json_output = json_decode($pageContent);  
  
 // Confirm that results were returned before parsing
 if (!is_null($json_output->query->results)) {
    if ($x != "") {
      $y = $json_output->query->results->json->src;
      echo "<html><body onload=' var sl=parent.document.getElementById(\"" . $x . "\"); if (sl != null) { if (sl.value == \"\") { sl.value=\"" . $y . "\";  }  }  '>" . $json_output->query->results->json->sentences->trans . "</body></html>";
    } else {
      echo "<html><body>" . $json_output->query->results->json->sentences->trans . "</body></html>";
    }
 }

}
?> 

