function Translate($word, $conversion = 'hi_to_en')
{
    $translator = new MicrosoftTranslator("ZWXY16Y45VGP/tLUWwkikzop8iuzPBBcqzhtqpO4+zU");
    $translator->translate("en", "hi", $word);
    $data = json_decode($translator->response->jsonResponse, true);
    return strip_tags($data["translation"]);
}
Example #2
0
<?php

require "header.php";
//TTTTTTTTTTT for the translator TTTTTTTTTTTTTTTTTT
require_once 'plug-in/translate/config.inc.php';
require_once 'plug-in/translate/class/ServicesJSON.class.php';
require_once 'plug-in/translate/class/MicrosoftTranslator.class.php';
$translator = new MicrosoftTranslator(ACCOUNT_KEY);
$selectbox = array('id' => 'txtLang', 'name' => 'txtLang');
$translator->getLanguagesSelectBox($selectbox);
//LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL
//require("search.php");
require_once BUSINESS_DIR_ENTRY . "EntryManager.php";
require_once BUSINESS_DIR_TRANSLREQ . "TranslationRequestManager.php";
require_once BUSINESS_DIR_SUBSCRIPTION . 'Subscription.php';
require_once BUSINESS_DIR_SUBSCRIPTION . 'SubscriptionManager.php';
require_once BUSINESS_DIR_USER . 'User.php';
require_once BUSINESS_DIR_USER_LOGIN . 'UserLoginManager.php';
//require DB_CONNECTION . 'DBHelper.php';
//require DB_CONNECTION . 'datainfo.php';
$lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
// 1
//$lang = 'ru';
//echo "the language: " . $lang;
$em = new EntryManager();
$trm = new TranslationRequestManager();
$aryOfEntry = $em->getListOfEntryBriefByLanguage($lang);
$aryOfTreq = $trm->getListOfTreqByLang($lang);
?>
<div id="index_table_container" align="center">
  <!-- left column -->
 /**
  * Get the translation from a given string using Bing Translate API
  */
 public function getBingTranslation()
 {
     if (!AccountManager::getInstance()->isLogged()) {
         return JsonResponseBuilder::failure();
     }
     $str = $this->getRequestVariable('str');
     $lang = AccountManager::getInstance()->vcsLang;
     $translation = false;
     $str = str_replace("\n", "[@]", $str);
     $bing = new MicrosoftTranslator("0Iwzej5BJeHK/2nvHh7/uJyHLhmnyFJEAuOYOfJ1QLg=");
     $bing->translate('en', $lang, $str);
     $bing->response->jsonResponse;
     preg_match("/<string xmlns=\"(.[^\"]*)\">(.*)?<\\/string>/e", $bing->response->translation, $match);
     // Replace new line mark
     $translation = str_replace("[@]", "<br>", $match[2]);
     // Few substitutions
     $translation = str_replace("&amp;", "&", $translation);
     $translation = str_replace("&amp;  ", "&", $translation);
     $translation = str_replace("&#39;", "'", $translation);
     $translation = str_replace("&quot;", '"', $translation);
     $translation = str_replace("&lt;", '<', $translation);
     $translation = str_replace("&gt;", '>', $translation);
     return JsonResponseBuilder::success(array('translation' => $translation));
 }
Example #4
0
<?php

/**
 * This file will retuen JSON response
 */
require_once 'config.inc.php';
require_once 'class/ServicesJSON.class.php';
require_once 'class/MicrosoftTranslator.class.php';
$translator = new MicrosoftTranslator(ACCOUNT_KEY);
$text_to_translate = $_REQUEST["text"];
$to = $_REQUEST['to'];
//$from = $_REQUEST['from'];  //NOTICE:There is no "from" from URL;
$from = '';
$format = '';
$translator->translate($from, $to, $text_to_translate, $format);
echo $translator->response->jsonResponse;
Example #5
0
<?php

require_once dirname(__FILE__) . "/MicrosoftTranslator.php";
// Load MicrosoftTranslator Class ...
$MicrosoftTranslator = new MicrosoftTranslator();
// Call MicrosoftTranslator Class
$array = array('username' => '{live login}', 'key' => '{Azure account key}', 'text' => '{text}', 'to' => '{translate Language}', 'from' => '{Text Language}');
$MicrosoftTranslator->set($array);
// Set All Variables As Array
echo $MicrosoftTranslator->translate();
// translate output
<?php

/**
 * This file will retuen JSON response
 */
require_once 'config.inc.php';
require_once 'class/ServicesJSON.class.php';
require_once 'class/MicrosoftTranslator.class.php';
$translator = new MicrosoftTranslator(ACCOUNT_KEY);
$text_to_translate = $_REQUEST['text'];
$to = $_REQUEST['to'];
$from = $_REQUEST['from'];
$translator->translate($from, $to, $text_to_translate);
echo $translator->response->jsonResponse;
<?php

require_once 'config.inc.php';
require_once 'class/MicrosoftTranslator.class.php';
//ACCOUNT_KEY you have to get from https://datamarket.azure.com/dataset/1899a118-d202-492c-aa16-ba21c33c06cb
$translator = new MicrosoftTranslator("ZWXY16Y45VGP/tLUWwkikzop8iuzPBBcqzhtqpO4+zU");
$text_to_translate = 'Hello World';
$from = 'en';
$to = 'es';
$translator->translate($from, $to, $text_to_translate);
print_r($translator);
$data = json_decode($translator->response->jsonResponse, true);
echo $data["translation"];